grep command in unix with example
Posted on | January 15, 2010 | No Comments
Grep command is very useful in UNIX.Grep searches for similar pattern on file and return the result.Example of grep command is
grep ‘word’ filename – Will return the line which contain word.
grep -i ‘nocase’ filename – This option will make grep case insensitive.
grep – r ‘sear’ /etc/ – This will search in the whole directory recursively
grep “boo” filename – This will display line which contain exact match of the word boo.
egrep -w ‘word1|word2′ filename – This will search for both the word1 and word2 in the filename.
grep – c word1 filename – Will return the number of lines where word1 is found.
grep -v word1 filename – Will return the line which doesn’t contain the word1.
grep word1 * – Will search for occurence of word1 in whole directory
grep ^a.ad fruitlist.txt – Print line that contain the letter followed by a and in last contain letter ad.
Comments
Leave a Reply