Wednesday, February 11, 2009

GREP examples

grep [options] PATTERN [FILES]


Option Meaning

-c print a count of the number of lines that match

-E turn on extended expressions

-h suppress the normal prefixing of each o/p line
with the name of the file it was found in

-i ignore case

-l list the name of the files with matching lines,
don't o/p the actual matched lines

-v invert the matching pattern to select non matching lines
rather than matching lines



Ex:- grep e$ *
to look for files in the current directory that have lines that end with letter e.

Ex:- grep a[[:blank:]] *
we want to find lines with words that end with a in all the files in current directory

Ex:- grep Th.[[:space:]] *

to find three - letter words that start with Th, in all the files in current directory


Ex:- grep -E [a-z]\{10\} *
To use the extended grep mode to search for lowercase words that are exactly 10 characters long

EX: Recursively check a folder to find the given text using grep
grep -R "text" *

No comments:

Post a Comment