如何从另一个文件A中删除出现在文件B上的行? [英] How to remove the lines which appear on file B from another file A?

查看:155
本文介绍了如何从另一个文件A中删除出现在文件B上的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的文件A (由电子邮件组成),每封邮件一行。我还有另一个包含另一组邮件的文件B



我将使用哪个命令删除文件B中出现的所有地址从文件A。



所以,如果文件A包含:

  A 
B
C

和文件B包含:

  B 
D
E

然后文件A应该留有:

  A 
C

现在我知道这是一个可能更常被问到的问题,但我只找到一个在线命令,它给了我一个错误的分隔符。



任何帮助将不胜感激!有人肯定会想出一个聪明的单行程式,但我不是shell专家。

comm -23 file1 file2

-23可以抑制两个文件中的行,或只在文件2中。文件必须被排序(它们在你的例子中),但如果没有,请通过 sort 第一个...



请参阅手册页


I have a large file A (consisting of emails), one line for each mail. I also have another file B that contains another set of mails.

Which command would I use to remove all the addresses that appear in file B from the file A.

So, if file A contained:

A
B
C

and file B contained:

B    
D
E

Then file A should be left with:

A
C

Now I know this is a question that might have been asked more often, but I only found one command online that gave me an error with a bad delimiter.

Any help would be much appreciated! Somebody will surely come up with a clever one-liner, but I'm not the shell expert.

解决方案

comm -23 file1 file2

-23 suppresses the lines that are in both files, or only in file 2. The files have to be sorted (they are in your example) but if not, pipe them through sort first...

See the man page here

这篇关于如何从另一个文件A中删除出现在文件B上的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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