我怎么能比较两个文件,​​并在其中删除类似的行(bash脚本) [英] How could I compare two files and remove similar rows in them (bash script)

查看:125
本文介绍了我怎么能比较两个文件,​​并在其中删除类似的行(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

这是进程替换

这篇关于我怎么能比较两个文件,​​并在其中删除类似的行(bash脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆