【发布时间】:2019-05-30 17:52:39
【问题描述】:
我有一个大文件,想从文件中删除包含另一个文件中列出的确切字符串的所有行。但是,字符串必须完全匹配(对不起,我不知道如何更好地描述这一点)。
这是文件:
one@email.com,name,surname,city,state
two@email.com,name,surname,city,state
three@email.com,name,surname,city,state
anotherone@email.com,name,surname,city,state
这里是过滤的示例列表:
one@email.com
three@email.com
想要的输出是:
two@email.com,name,surname,city,state
anotherone@email.com,name,surname,city,state
我尝试使用以下方法来做到这一点:
grep -v -f 2.txt 1.txt > 3.txt
但是这会产生输出:
two@email.com,name,surname,city,state
我认为它这样做是因为“anotherone@email.com”包含“one@email.com”。我已经搜索了一种包含行首的方法,但没有找到任何合适的方法。
我也愿意做 grep 以外的事情,我使用 grep 是因为我想不出任何其他方式。
【问题讨论】:
-
three@email.com != three@gmail.com
-
如果你使用 GNU grep 添加选项
-w.