Wednesday, January 12, 2011

grep - the coolest Unix command ever :)


This is a cool Unix command.

The grep command searches the given file for lines containing a match to the given strings or words. By default, grep displays the matching lines. Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines.

Usage Examples:

$ grep ath /etc/passwd

> simple search for a word in a single file


$ grep -r "192.168.1.1" /etc/

> search through the files within a folder


$ egrep -w -i 'thomas|david' filename

> search for 2 words in a single line