# grep
GREP = Global Regular Expression search & Print
# Use cases
- Log analysis: Search log files for errors, warnings, or specific events.
- Configuration file editing: Find and modify specific settings in configuration files.
- Code searching: Locate specific functions, variables, or code patterns in source code.
- Text file processing: Extract or filter specific data from text files.
- System administration: Identify potential issues or monitor system activity by searching log files.
# Examples
Find all lines containing "error" in the file "system.log":
grep "error" system.log
# Search Multiple Files
Search for "config" in all .txt files in the current directory:
grep "config" *.txt
# Case-Insensitive Search
Find all occurrences of "admin" (ignoring case) in the file "users.txt":
grep -i "admin" users.txt
# Line Numbers
Print the line numbers and lines containing "root" in "passwd":
grep -n "root" passwd
# Regular Expressions
Find all lines starting with a digit in "data.csv":
grep "^[0-9]" data.csv
# Counting Matches
Count the number of lines with "warning" in "messages.log" (without showing the lines):
grep -c "warning" messages.log