0

次のコードを使用して、input_file から最初の列に特定の値を持つ行を抽出します。行の抽出に基づく値は、「one_column.txt」にあります。

while read file
do
awk -v col="$file" '$1==col {print $0}' input_file >> output_file
done < one_column.txt

私の質問は、最初の列がone_column.txt のどの値とも一致しない行を抽出するにはどうすればよいですか? 言い換えれば、input_file から output_file に終わらない残りの行だけを抽出するにはどうすればよいでしょうか?

4

1 に答える 1

1

grep -vfそれを作ることができます:

 grep -vf output_file input_file

grep -fあるファイルを別のファイルと比較します。grep -v反対に一致します。

テスト

$ cat a
hello
good
bye
$ cat b
hello
good
bye
you
all
$ grep -f a b
hello
good
bye
$ grep -vf a b ## opposite
you
all
于 2013-09-10T09:29:16.587 に答える