如何从另一个文件 A 中删除出现在文件 B 上的行? [英] How to remove the lines which appear on file B from another file A?
问题描述
我有一个很大的文件 A(由电子邮件组成),每封邮件一行.我还有另一个文件 B,其中包含另一组邮件.
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.
我将使用哪个命令从文件 A 中删除出现在文件 B 中的所有地址.
Which command would I use to remove all the addresses that appear in file B from the file A.
所以,如果文件 A 包含:
So, if file A contained:
A
B
C
和文件 B 包含:
B
D
E
然后文件 A 应该留下:
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.
任何帮助将不胜感激!肯定有人会想出一个聪明的单线,但我不是 shell 专家.
Any help would be much appreciated! Somebody will surely come up with a clever one-liner, but I'm not the shell expert.
推荐答案
如果文件已排序(它们在您的示例中):
If the files are sorted (they are in your example):
comm -23 file1 file2
-23
抑制在两个文件中或仅在文件 2 中的行.如果文件未排序,首先通过 sort
管道它们...
-23
suppresses the lines that are in both files, or only in file 2. If the files are not sorted, pipe them through sort
first...
请参阅此处的手册页
这篇关于如何从另一个文件 A 中删除出现在文件 B 上的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!