grep command is used to find out the word from the file and pull those line to display on terminal. Everyone using grep command in different way for different data to pull for somehow same intent.
On day-to-day basis you as a technical member with different role ( developer/admin/tech Lead) or any another role will have to use somewhere to pull out some data from the linux server from specific file or files or from folder. Linux
grep command is very helpful which provide you required information form huge data set.
Let us discuss some of the example of usage of
grep for the different purpopses below.
Exclude word in grep
grep -v "word" file
search a word recursively from all files in a folder
grep -r 'time out' /opt/apache/tomcat7/logs/
exclude word using perl regular expression
If your grep supports Perl regular expression with -P option you can do (if bash; if tcsh you’ll need to escape the !):
grep -P '(?!.*unwanted_word)keyword' file