Tuesday, May 29, 2012
6:22 PM

Highlighting the output of grep

grep is used for searchin for a string or a pattern in a given input stream. By default the grep ouputs the whole line in which the search string is found.
For e.g. if we have a file "info" as below
info



If we want to search for the string "linux" we would do it as follows



output



Note: By default grep is case sensitive.
In the above line, the search string is not differentiated from the whole line in any way. But if we want to hightlight the search string in the result of the grep we can do it by passing the option --color i.e



output :
Welcome to linux, a free operating system

In the above output the search string "linux" has been hightlighted, thus differentiating the search string clearly from the rest of the text.

0 comments:

Post a Comment