Link to home
Start Free TrialLog in
Avatar of shchong2
shchong2

asked on

What is the difference btw "grep" and "egrep" ???

What is the difference btw "grep" and "egrep" ???
Pls kindly elaborate if there's difference(s).
Thx =)
Avatar of sunnycoder
sunnycoder
Flag of India image

egrep
egrep stands for extended grep. You can do everything with egrep that you can do with grep. And it is probably somewhat better to use, but grep is a lot easier to remember.  The main difference is that you can use some extra symbols in egrep that let you search for strings in even fancier ways.
http://www.geog.ucsb.edu/classes/Geog013/chapt6_s1.html
http://people.ucsc.edu/~syncope/ling80g/grep.html

for more info ... refer to man pages
Avatar of chris_calabrese
chris_calabrese

Also, most modern grep implemenations actually do everything that egrep does if you use 'grep -E'
Also too, egrep use a diferent way to manage the search for the regular expressions and so it resource needs are different from grep (you should be aware of that if you have very low resources or your search is particularily complex). It is supposed to let you make extensive use of reg-exps. but today common grep implementations give you enough power to use them extensively (it wasn't this way on the original implementations).

You should also check for 'fgrep' (fast-grep) which make it's searches based only on fixed-strings (no reg-exp) and is a lot faster than the other two if you just need to lookup for fixed strings.
Actually, grep, egrep, and fgrep are usually the same binary on most modern implemenations, and there are no performance or resource differences between them given the same search expression. In fact, egrep == 'grep -E' and fgrep == 'grep -F'

The only difference is the complexity of the search expressions they allow (simple string, simple regular expression, extended regular expression).

This wasn't true of early grep/egrep/fgrep implementations, but it is true for modern implementations.

Early implementations used different pattern matching algorithms that were optimized for different circumstances. But with the dicovery of the Boyer-Moore string-matching algorithm in the 1980's, there is no longer any need to use different algorithms as B-M is the optimum algorithm in all three situations.
simply put, as from this man page entry...
"
Plain call with pattern
      grep [-E|-F] [-c|-l|-q] [-bhinsvwx] pattern [file ...]

    Call with (multiple) -e pattern
      grep [-E|-F] [-c|-l|-q] [-bhinsvwx] -e pattern...  [-e pattern] ...
           [file ...]
"
grep allows for a search of a single pattern/expression from a file.
egrep (grep -E) allows for multiple pattern search.
ASKER CERTIFIED SOLUTION
Avatar of ChiefEngineer
ChiefEngineer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial