Solved

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

Posted on 2003-11-12
6
5,476 Views
Last Modified: 2008-01-09
What is the difference btw "grep" and "egrep" ???
Pls kindly elaborate if there's difference(s).
Thx =)
0
Comment
Question by:shchong2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9730797
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
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 9731911
Also, most modern grep implemenations actually do everything that egrep does if you use 'grep -E'
0
 
LVL 1

Expert Comment

by:ChiefEngineer
ID: 9732530
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:chris_calabrese
ID: 9733273
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.
0
 

Expert Comment

by:zile26
ID: 9742654
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.
0
 
LVL 1

Accepted Solution

by:
ChiefEngineer earned 20 total points
ID: 9742842
I'm affraid zile26 got confused with the case of the switches (remember Unix is case-sensitive).
His comment treat '-E' and '-e' as being the same when they're actually not:
'-E' stands for 'Extended' behavior while '-e' stands for 'expression pattern' to search for. That means that they serve different purposes and they can even be combined, as shown in the man page he posted here.

In short:

   grep <pattern>

  will search for <pattern> using simple regular expressions,

   grep -E <pattern>

  will search for <pattern> allowing use of Extended Regular Expressions,

  grep -e <pattern1> -e <pattern2> -e <pattern3>

  will search for any of <pattern1>, <pattern2> and <pattern3> using simple regular expressions, and finally

  grep -E -e <pattern1> -e <pattern2> -e <pattern3>

  will search for any of <pattern1>, <pattern2> and <pattern3> allowing use of Extended Regular Expressions.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question