从一个文件中删除线,是在另一个文件 [英] Deleting lines from one file which are in another file
本文介绍了从一个文件中删除线,是在另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件 F1
:
line1
line2
line3
line4
..
..
我要删除所有这一切都在另一个文件 F2行
:
line2
line8
..
..
我试着用猫
和东西 SED
,它甚至还没有接近我意。我怎样才能做到这一点?
I tried something with cat
and sed
, which wasn't even close to what I intended. How can I do this?
推荐答案
的grep -v -x -f F2 F1
应该做的伎俩。
说明:
-
-v
选择不匹配的行 -
-x
来匹配整行仅 -
-f F2
得到F2模式
-v
to select non-matching lines-x
to match whole lines only-f f2
to get patterns fromf2
我们可以改用 -F F2
匹配的固定字符串的从 F2
而比的模式的(如果你想删除该行的你所看到的,如果你得到了什么的方式,而不是在 F2
治疗以线条为正则表达式模式)。
One can instead use -F f2
to match fixed strings from f2
rather than patterns (in case you want remove the lines in a "what you see if what you get" manner rather than treating the lines in f2
as regex patterns).
这篇关于从一个文件中删除线,是在另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文