What is the difference between grep -e and grep -E option?
-e
is strictly the flag for indicating the pattern you want to match against. -E
controls whether you need to escape certain special characters.
man grep
explains -E
it a bit more:
Basic vs Extended Regular Expressions
In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \).
Traditional egrep did not support the { meta-character, and some egrep implementations support \{ instead, so portable scripts should avoid { in grep -E patterns and should use [{] to match a
literal {.
GNU grep -E attempts to support traditional usage by assuming that { is not special if it would be the start of an invalid interval specification. For example, the command grep -E '{1' searches for
the two-character string {1 instead of reporting a syntax error in the regular expression. POSIX.2 allows this behavior as an extension, but portable scripts should avoid it.
Also grep -e
allows to use several strings for searching: 'grep -e 'abc' -e 'def' -e '123'
will look for any of the three of these strings: abc
as well as def
and 123
.
This works quite similar to grep 'abc\|def\|123'
where \|
stands for or
but could be a bit clearer to read.
As the most important facts on grep -E
are already explained here, I just want to add what I summed up on this topic on a quite similar question: Regular Expression for finding double characters in Bash
see below
/extended
grep understands three different versions of regular expression syntax: “basic,” “extended” and “perl.” In GNU grep, there is no difference in available functionality between basic and extended syntaxes. In other implementations, basic regular expressions are less powerful. The following description applies to extended regular expressions; differences for basic regular expressions are summarized afterwards. Perl regular expressions give additional functionality, and are documented in pcresyntax(3) and pcrepattern(3), but may not be available on every system.
So, once again.
In GNU grep, there is no difference in available functionality between basic and extended syntaxes