Monday, September 27, 2010

Difference between grep, egrep and fgrep?

a) grep: Search for a Pattern  in the named input files.

Example: 

% cat text
Hiii

How r u...

fish

fishes

fisherman

Excellent

%  grep fish text

fish
fishes
fisherman

b) egrep:  (grep -E in linux is -E, --extended-regexp ) Extended grep where additional regular expression metacharacters have been added like ^, $,*,.,|,\,+, ?, | and ().
Example:

% grep -E '^fish' text

fish
fishes
fisherman

c) fgrep: (grep -F in linux is -F, --fixed-strings) Fixed or fast grep and behaves as grep but does not recognise any regular expression metacharacters as being special.

Example: 

% grep -F fish text

fish
fishes
fisherman

No comments:

Post a Comment