Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am preparing for a Linux terminal assessment now, I tried to Google and found most resources are referring to the basic "grep" rather than the more powerful "egrep" -- well, that is at least what the professor said in lecture.

I am always working with small samples so performance tuning is a thing too far away.

So basically I'd like to know are there any areas where I must switch to egrep to do it in a better way? Is it safe to work with basic "grep" as for now? will there be potential risks?

Sorry about my limited knowledge on Linux shell commands, the man page looks like a maze to me and honestly I haven't put much time in understanding all the features both command provide.

share|improve this question

migrated from stackoverflow.com Apr 8 '10 at 8:09

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 9 down vote accepted

egrep = grep -E

From http://www.opengroup.org/onlinepubs/007908799/xcu/grep.html

"Match using extended regular expressions. Treat each pattern specified as an ERE, as described in the XBD specification, Extended Regular Expressions . If any entire ERE pattern matches an input line, the line will be matched. A null ERE matches every line."

So, with egrep you can use +, ?, | and ().

share|improve this answer
    
@omfgroflmao : is that all the difference? well, now I feel comfortable to just focus on the "grep" tutorials without worrying about the "egrep" command :) Thanks for your tip! –  Michael Mao Apr 7 '10 at 2:09
    
You're welcome. –  Anonymous Apr 7 '10 at 3:59
1  
Whether you call it egrep or grep -E, extended regular expressions do generally make complex patterns shorter and therefore easier to read by removing a lot of ``. It's not about performance, but is a better way in some sense. –  Jefromi Apr 7 '10 at 4:42

egrep is deprecated. Use grep -E. Note that grep finds string patterns for you. If you want to do something to your strings after finding them, then you have to pipe to a string processing tool such as awk (or the shell). The tool you should alos look into is awk, as awk finds strings for you as well much like grep and does the processing for you if you need. It has all the things grep/sed/etc do in one handy tool.

share|improve this answer
    
@ghostdog74 : ahhh, so egrep is recommended not to be used... I thought it was the replacement for grep... Thanks for your tip! –  Michael Mao Apr 7 '10 at 3:39
1  
Just for the record, on many machines, mine included, egrep is a link to grep. That is, they are actually the same exact command, but behave differently depending on how you call them. –  MJB Apr 7 '10 at 16:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.