1

以下に2つのファイルがあります。

$cat file1
"2020051576BPI";"TS.1.BPI.20121129120000.005.txt";"Error";"'OF_USM_DBTI0000029'/'CO_SERVICE_SVCID11066'/'CO_FA_SC_600224'/. appears less times in the Input File (0), but should appear at least 1 times";""
"2019707951BPI";"TS.1.BPI.20121129120000.014.txt";"Error";"'OF_USM_DBTI0000029'/'CO_SERVICE_SVCID11066'/'CO_FA_SC_600224'/. appears less times in the Input File (0), but should appear at least 1 times";""
"Failed to parse string. Error msg: Failed to parse 'Fatal Error at file (buffer) "", line 366, column 17   Message: Expected whitespace'"

$cat file2
"'OF_USM_DBTI0000029'/'CO_SERVICE_SVCID11066'/'CO_FA_SC_600224'/. appears less times in the Input File (0), but should appear at least 1 times"
"Failed to parse string. Error msg: Failed to parse 'Fatal Error at file (buffer) "", line 366, column 17   Message: Expected whitespace'"

file2を読んでいて、grepを使用して、file1(大きなファイル)の行を見つけています。私はそれを以下のようにやっています:

$cat file2|while read line
do
grep $line file1
done

しかし、私は以下のように結果を下回っています:

grep: can't open appears
grep: can't open less
grep: can't open times
grep: can't open in
grep: can't open the
grep: can't open Input
grep: can't open File
grep: can't open (0),
grep: can't open but
grep: can't open should
grep: can't open appear
grep: can't open at
grep: can't open least
grep: can't open 1
grep: can't open times"
USM_GRPSET_BPI_ERROR_20121130_171648.TXT:"2020051576BPI";"TS.1.BPI.20121129120000.005.txt";"Error";"'OF_USM_DBTI0000029'/'CO_SERVICE_SVCID11066'/'CO_FA_SC_600224'/. appears less times in the Input File (0), but should appear at least 1 times";""
USM_GRPSET_BPI_ERROR_20121130_171648.TXT:"2019707951BPI";"TS.1.BPI.20121129120000.014.txt";"Error";"'OF_USM_DBTI0000029'/'CO_SERVICE_SVCID11066'/'CO_FA_SC_600224'/. appears less times in the Input File (0), but should appear at least 1 times";""
grep: can't open to
grep: can't open parse
grep: can't open string.
grep: can't open Error
grep: can't open msg:
grep: can't open Failed
grep: can't open to
grep: can't open parse
grep: can't open 'Fatal
grep: can't open Error
grep: can't open at
grep: can't open file
grep: can't open (buffer)
grep: can't open "",
grep: can't open line
grep: can't open 366,
grep: can't open column
grep: can't open 17
grep: can't open Message:
grep: can't open Expected
grep: can't open whitespace'"
USM_GRPSET_BPI_ERROR_20121130_171648.TXT:"2019714006BPI";"TS.1.BPI.20121129120000.005.txt";"Error";"Failed to parse string. Error msg: Failed to parse 'Fatal Error at file (buffer) "", line 366, column 17   Message: Expected whitespace'";""
4

4 に答える 4

4

あなたが探しているものを引用してみてください:

while read line
do
  grep -F "$line" file1
done < file2
于 2012-12-05T13:53:01.323 に答える
2

パターンを引用する必要があります。

しかし、あなたが実際にすべきことは、スイッチを介しfile2てgrepするために直接の文字列を提供することだと思います-f

grep -Ff file2 file1

次に、 の固定文字列がfile2から grep されfile1ます。

の行が正規表現の場合は、スイッチfile2を省略してください。-F

于 2012-12-05T15:27:35.973 に答える
0

grepの最初のパラメーターに二重引用符を追加します

grep "$line" file1

また

grep "${line}" file1
于 2012-12-05T13:53:24.293 に答える
0

引用符を使用して、 cat の無用な使用を削除します。

while read line
do
  grep -F "$line" file1
done < file2 
于 2012-12-05T14:15:51.400 に答える