我必须这样的文件:
文件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
关于bash - 如果第一列出现在另一个文件中,则从文件中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39214614/