![]() You can also use command-line option "C" instead of "-context" for example Show an additional six lines after matching very useful to see what is around and to print the whole message if it splits around multiple lines. This grep command example will search for the word "Exception" in logfile.txt and print them but since we have piped out of the first grep command to the second grep command which will exclude all lines which match the word "ERROR".īelow an example of grep command in UNIX will print 6 lines around the matching line of word "successful" in logfile.txt Grep Exception logfile.txt | grep -v ERROR Most of the time I look for Exception and Errors in log files and sometimes I know certain Exception I can ignore so I use the grep -v option to exclude those Exceptions Grep command is also part of any beginner's UNIX command tutorial as it is an essential command to learn in order to work efficiently in any UNIX environment like Redhat Linux, Ubuntu, IBM AIX, Oracle Solaris, or BSD.Īnyway, these examples are by no means complete so please contribute you're own grep command tips or how you are using grep in Linux to make it more useful and allow all of us to benefit from each other's experience and work efficiently in UNIX or Linux.Įxample 1: How to ignore some words while doing a search using grep in UNIXįinding relevant words and exclusion of irrelevant words. ![]() ![]() The following examples of grep command in UNIX are based on my experience and I use them on a daily basis in my work. 10 ways to use Grep command in Unix - examples
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |