【发布时间】:2016-08-29 20:24:26
【问题描述】:
我必须像这样的文件:
文件1:
id1 junk junk junk
id2 junk junk junk
id3 junk junk junk
id4 junk junk junk
文件2:
id2
id3
如何从 File1 中删除在 File2 中具有 id 的 2 行。所以输出将是
id1 junk junk junk
id4 junk junk junk
谢谢
【问题讨论】:
我必须像这样的文件:
文件1:
id1 junk junk junk
id2 junk junk junk
id3 junk junk junk
id4 junk junk junk
文件2:
id2
id3
如何从 File1 中删除在 File2 中具有 id 的 2 行。所以输出将是
id1 junk junk junk
id4 junk junk junk
谢谢
【问题讨论】:
使用 awk 你可以做到这一点:
awk 'FNR==NR{a[$1]; next} !($1 in a)' file2 file1
id1 junk junk junk
id4 junk junk junk
或将grep -v 与进程替换一起使用:
grep -vf <(sed 's/.*/^&[[:blank:]]/' file2) file1
id1 junk junk junk
id4 junk junk junk
【讨论】:
您可以告诉 grep 从 file2 中排除所有内容
grep -vf file2 文件1
【讨论】: