What are the differences between grep,
egrep? What are some examples of using them differently?
The variant programs
rgrepare the same as
grep -F, and
grep -r, respectively. These variants are deprecated, but are provided for backward compatibility.
Pattern Syntax -E, --extended-regexp Interpret PATTERNS as extended regular expressions (EREs, see below). -F, --fixed-strings Interpret PATTERNS as fixed strings, not regular expressions. -G, --basic-regexp Interpret PATTERNS as basic regular expressions (BREs, see below). This is the default. -P, --perl-regexp Interpret PATTERNS as Perl-compatible regular expressions (PCREs). This option is experimental when combined with the -z (--null-data) option, and grep -P may warn of unimplemented features.
grep -Fwhenever you have no pattern to match as it is a lot faster.
grep -Eand especially
grep -Ponly when Basic Regex does not fullfil your needs as the matching will be slower.
What's Difference Between Grep, Egrep and Fgrep in Linux? - TecMint explains the difference well. All three do the same thing with the same code, but have different options.
egrep is the same as
-E, interpreting PATTERN as an extended regular expression. It treats meta-characters as is and doesn't substitute them as strings like in the original
grep, which is used by Ubuntu, has no difference in available functionality between basic and extended syntax (unlike the original
grep found in some other distros).
fgrep is the same as
-F. interpreting PATTERN as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to be matched. It doesn't recognize regular expressions, nor any meta-characters. For searching any direct string, it's faster, so this is the version of
grep which should be selected.