grep -eとgrep -Eオプションの違いは何ですか?

grep -eとgrep -Eオプションの違いは何ですか?

grep -eの違いを理解しようとしていますgrep -E。今grep manpage私は次を得ます:

-E, --拡張正規表現

PATTERNを拡張正規表現として解釈します(下記参照)。

-e モード、 --regexp=モード

- で始まるパターンを保護するのに便利なパターンとしてPATTERNを使用します。

上記の説明は私には理解できません。

それでは、誰かが私に2つexamplesの違いといつどのオプションを使用するべきかを説明できますか?

PS:バージョン:grep(GNU grep)2.10

ベストアンサー1

-e厳密に言えば、一致するパターンを表すフラグです。-E特定の特殊文字をエスケープする必要があるかどうかを制御します。

man grep-E詳しく説明するには:

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.

おすすめ記事