文字列「methodname(」を探したいのですが、「(」をエスケープできません。どうすれば取得できますか?
grep methodname( *
また
ack-grep methodname( *
働く?
を解釈するものは 2 つあります。(シェルとack-grep.
''、""、またはを使用して、シェルから\エスケープすることができます。(
grep 'methodname(' *
grep "methodname(" *
grep methodname\( *
grepデフォルトで基本的な正規表現言語を使用するため、(特別なものではありません。(egrepまたはgrep -Eまたはを使用した場合になりますgrep -P。)
一方、ack-grepPerl の正規表現を入力として受け取ります(が、これも特殊なので、それもエスケープする必要があります。
ack-grep 'methodname\(' *
ack-grep "methodname\\(" *
ack-grep methodname\\\( *
ack-grep 'methodname[(]' *
ack-grep "methodname[(]" *
ack-grep methodname\[\(\] *
\の前にa を追加してみてください(。
小さなデモ:
$ cat file
bar
methodname(
foo
$ grep -n methodname\( file
2:methodname(
$
パターンを一重引用符または二重引用符で囲むこともできます。
$ grep -n 'methodname(' file
2:methodname(
$ grep -n "methodname(" file
2:methodname(
$