nothing is impossible!!!!

nothing is impossible!!!!

Wednesday, August 20, 2008

grep, egrep and fgrep from manpage

grep
grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.

egrep
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below).

fgrep
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.

Important Options with grep :
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.
--exclude-dir=DIR
Exclude directories matching the pattern DIR from recursive searches.
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines. Places a line containing a group separator (--) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.
-n, --line-number
Prefix each line of output with the 1-based line number within its input file.
-c, --count
Suppress normal output; instead print a count of matching lines for each input file.
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input files.


egrep is the same as grep -E.
fgrep is the same as grep -F.
rgrep is the same as grep -r.

grep Repetition
A regular expression may be followed by one of several repetition operators:
? The preceding item is optional and matched at most once.
* The preceding item will be matched zero or more times.
+ The preceding item will be matched one or more times.
{n} The preceding item is matched exactly n times.
{n,} The preceding item is matched n or more times.
{,m} The preceding item is matched at most m times.
{n,m} The preceding item is matched at least n times, but not more than m times.

No comments: