The grep command is used to search the pattern or pattern of words or character in a file(s), and pull those lines to display on the terminal. This is a most important command in Linux, everyone using the grep command in different ways for different set data to pull, for somehow the same intent.
1. overview of grep command
grep command in Linux or grep command in UNIX or grep command in mac, the objective is one to pull the data which match the pattern of character. On a day-to-day basis, you as a technical member with a different role ( developer/admin/tech Lead) or any other role will have to use somewhere to pull out some data from the Linux server from specific files or files or from the folder. Linux
grep command is very helpful which provide you required information form huge data set. You can visit all Linux post on Linux tutorial page
Let us discuss some of the example of usage of
grep for the different purpopses below.
2. Exclude word in grep command
Thisis the syntax and you can use your own various grep command examples.
grep -v "word" file
3. recursive search from all files in a folder
You can use grep command example to search a pattern.
grep -r 'time out' /opt/apache/tomcat7/logs/
4. 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
You can go for reference to Linux official site
Happy Learning of Linux grep command.