Pages

Tuesday 6 September 2011

GREP


GREP is a command line search utility or tool  to filter the input given to it. Grep got its name from ed editor as g/re/p (global / regular expression / print).
In this post we will see how to use grep in detail and next post with the help of regular expressions.
GREP command syntax
grep options searchterm filename

or

command | grep options searchterm 
For searching a word in file
 grep 'ada' filename
For search a word which is either caps or small letters(i — case insensitive )
 grep -i 'ac' filename
inverse search for a word
 grep -v 'ac' filename
To count a word occurrence
 find -c ‘ac’ filename
Find ac characters along line numbers
 grep -n 'ac' filename
Find exact word ac
 grep -x 'ac' filename

No comments:

Post a Comment

Twitter Bird Gadget