![]() ![]() ![]() You can also create alias grep='grep -color' in your bash_profile file to avoid typing -color every time.ġ2) There are three versions of grep command in UNIX " grep, fgrep, and egrep". Now I have two bonus examples of grep command in UNIX:ġ1) grep command in UNIX can show a matching pattern in color which is quite useful to highlight the matching section, to see matching pattern in color use below command. Many times we gzip the old file to reduce the size and later want to look or find something on those files. grep -i command will find any occurrence of both Error, error, and ERROR and quite useful to display any sort of Error from the log file.Įxample 6: How to search patterns in gzip files using the zgrep command zgrep is another great version of grep command in Unix which is used to perform the same operation as grep does but with. If you want to do a case insensitive search then use -i option from the grep command in UNIX. Stands for extended grep and it is more powerful than grep command in Unix and allows more regular expression like you can use "|" option to search for either Error or Exception by executing just one command.Įxample 5: How to do case-insensitive searching using grep in Linux Prints two lines of context around each matching line.Įxample 4: How to search pattern using egrep and regular expression 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 |