Usage:grep keyword filename
1) How to ignore some words while doing search using grep in UNIX:
Example:
grep Exception logfile.txt | grep -v Error
2) How to count occurrence of a word in a file using grep command:
grep -c Exception logfile.txt
3) Printing lines after or before matching a word :
grep -C 6 Exception logfile.txt
4) How to search pattern using egrep and regular expression:
We can use '|' to search for either Error or Exception in single comand
egrep 'Error|Exception' filename.txt
5) -i can be used for case insensitive search
6) zgrep can be used to search patterns in gz files.
7) How to search a whole word in file using grep
grep -w word filename
1) How to ignore some words while doing search using grep in UNIX:
Example:
grep Exception logfile.txt | grep -v Error
2) How to count occurrence of a word in a file using grep command:
grep -c Exception logfile.txt
3) Printing lines after or before matching a word :
grep -C 6 Exception logfile.txt
4) How to search pattern using egrep and regular expression:
We can use '|' to search for either Error or Exception in single comand
egrep 'Error|Exception' filename.txt
5) -i can be used for case insensitive search
6) zgrep can be used to search patterns in gz files.
7) How to search a whole word in file using grep
grep -w word filename
No comments:
Post a Comment