Solved

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

Posted on 2003-11-12
6
5,466 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
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

786 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