我怎么能比较两个文件,​​并在其中删除类似的行(bash脚本)

问题描述:

我有列同样数量的数据,两个文件。我想文件2保存在另一个文件(文件3),而我排除这是在文件1​​已经存在的行。

I have two files of data with similar number of columns. I'd like to save file2 in another file (file3) while I exclude the rows which are existed already in the file1.

grep -v -i -f file1 file2> file3

但问题是,在文件1列之间的空间是\\ t的,而在另一方面,这是只,。因此,这个命令行不起作用。
任何建议??

But the problem is that the space between columns in the file1 is "\t" while in the other one it is just " ". Therefore this command line doesn't work. Any suggestion??

谢谢乡亲!

您可以制表符转换为空格飞:​​

You can convert tabs to spaces on the fly:

grep -vif <(tr '\t' ' ' < file1) file2 > file3

这是进程替换