【问题标题】:bash command to remove lines which are present in other text file [duplicate]bash命令删除其他文本文件中存在的行[重复]
【发布时间】:2020-05-20 02:16:26
【问题描述】:

我在 bash 我有两个文件 added.txt 和 unmatched.txt ,现在想象 added.txt 中的所有行都存在于 unmatched.txt 中。我想从 unmatched.txt 中删除 added.txt 中存在的行。例如

1) 添加.txt

apple
ball

2) unmatched.txt

cat
dog
apple
rar
ball

3) 需要的 output.txt

cat
dog
rar

【问题讨论】:

  • 这一点都不清楚,请在您的帖子中添加 3 件事。1- 输入样本,2- 预期输出样本和 3rd- 您的努力。请编辑您的帖子,然后让我们知道?
  • 感谢您在您的问题中添加示例,请在您提出的问题中也添加您的努力以解决您自己的问题。

标签: linux bash shell sh


【解决方案1】:

grep 无关:

$ cat added.txt
cat
dog
$ cat unmatched.txt
aardvark
cat
dog
giraffe
civet cat
$ grep -F -vx -f added.txt unmatched.txt
aardvark
giraffe
civet cat

仅打印与added.txt 的行不完全匹配的unmatched.txt 行(-v 颠倒了grep 的通常含义)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-12
    • 2014-10-13
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多