Solved

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

Posted on 2003-11-12
6
5,446 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
Comment Utility
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
Comment Utility
Also, most modern grep implemenations actually do everything that egrep does if you use 'grep -E'
0
 
LVL 1

Expert Comment

by:ChiefEngineer
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:chris_calabrese
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now