?
Solved

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

Posted on 2003-11-12
6
Medium Priority
?
5,493 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 80 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

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…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

777 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