When to use egrep instead of grep?

Solution 1:

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 ().

Solution 2:

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.