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 回答