Here are some commonly used grep options that enhance its functionality:
-
-i: Perform case-insensitive searching.grep -i "pattern" file.txt -
-c: Count the number of matching lines.grep -c "pattern" file.txt -
-n: Display line numbers along with matching lines.grep -n "pattern" file.txt -
-v: Invert the match, showing lines that do not match the pattern.grep -v "pattern" file.txt -
-ror-R: Recursively search through directories.grep -r "pattern" directory/ -
-l: List only the names of files with matching lines.grep -l "pattern" *.txt -
-e: Specify multiple patterns to search for.grep -e "pattern1" -e "pattern2" file.txt -
-A: Show lines after the match (e.g.,-A 3shows 3 lines after).grep -A 3 "pattern" file.txt -
-B: Show lines before the match (e.g.,-B 2shows 2 lines before).grep -B 2 "pattern" file.txt -
-C: Show lines around the match (e.g.,-C 2shows 2 lines before and after).grep -C 2 "pattern" file.txt
These options can be combined to refine your search. For example:
grep -i -n "pattern" file.txt
Feel free to ask if you need more information on any specific option!
