1

Windows7のコマンドプロンプトでGNUGrepを使用しています。

次のような内容のファイルjsutfstr.txtがあります。

some lines
HELLO("abc",adf)
HELLO("def", sd)
some lines
some lines
some lines

そして、 HELLO(..)パターンをgrepしたいと思います。Windowsのコマンドプロンプトで、次のものを使用しました。

C:\bin>Egrep     HELLO\(\"[^)]+\) jsutfstr.txt
HELLO("abc",adf)
HELLO("def", sd)

C:\bin>Egrep     HELLO\([^)]+\) jsutfstr.txt

したがって、2番目のパターンは何も生成しません。\ "を明示的に指定する必要がある理由がわかりません。[^)]は、二重引用符を含め、)と等しくないすべてのものと一致しませんか?

4

1 に答える 1

3

The problem is that you run in to the shell parsing the line first and ^ is the escape character for cmd. So the line that gets passed to grep in the second case is

Egrep     HELLO\([)]+\) jsutfstr.txt

while in the first case the " starts a quoted argument where cmd will not look into.

You can just quote the complete argument to avoid that:

Egrep "HELLO\([^)]+\)" jsutfstr.txt
于 2012-06-18T09:41:32.227 に答える