2012-03-22 5 views
2

ログファイルをいくつかの文字列を含むよりも線から消去しようとしています。文字列は、ファイル内にあり、ランダム[キーボード]文字で構成された[はいも*、+など] は*の正確なマッチングんgrepのように思える:私はfgrepは思っfgrepリテラルと一致する "*"

grep "abc*" logs :gives a matchine line 
blah_blah """abc*""" duh_duh 

However when I read it off the file it doesnt work with fgrep: 
cat file: 
"abc*" 
fgrep -f file logs => Matches nothing 

はgrepの+ Fと同じです[grep -f]これを実現させるためにfgrepで使用できるフラグがありますか?

ありがとうございます!

答えて

0

どのバージョンのgrepをお使いですか?すべては私のために正常に動作しますので、これはおそらく、最近のバージョンで修正されたバグかもしれ:

$ cat logs.txt 
blah_blah """abc*""" duh_duh 
$ cat patterns.txt 
"abc*" 
$ fgrep -f patterns.txt logs.txt 
blah_blah """abc*""" duh_duh 
$ fgrep --version 
GNU grep 2.6.3 
+0

また、私のために働く、fgrep 2.9 –

3

fgrepgrep -F、ないgrep -fと同等です。 -Fのオプションはパターンではなく固定文字列と一致します。リテラル文字列 "abc *"とマッチさせようとしているのであれば、 "ab"で始まり0以上の "c"文字が続く正規表現とは異なります。 、あなたが見ることができるように

[[email protected] ~]$ grep -f patterns.txt logs.txt 
ab 
blah_blah """abc*""" duh_duh 
abc 
[[email protected] ~]$ fgrep -f patterns.txt logs.txt 
blah_blah """abc*""" duh_duh 
[[email protected] ~]$ 

、パターンはgrepで正規表現として解釈されます。

[[email protected] ~]$ cat logs.txt 
ab 
blah_blah """abc*""" duh_duh 
abc 
[[email protected] ~]$ cat patterns.txt 
abc* 
[[email protected] ~]$ 

とgrepやfgrepの両方を試してみてください。

は、我々がで作業しているものを確立してみましょうリテラル文字列はfgrepとなります。

あなたは文字列またはパターンにマッチしているかどうかを確認して、あなたが使用する必要があるのgrepのバージョンを知っていますよ。

関連する問題