linux - 获取一个文件中不存在于另一个文件中的值

标签 linux bash shell loops sh

我有两个文件

文件1.txt:

docker/registry:2.4.2
docker/rethinkdb:latest
docker/swarm:1.0.0

文件2.txt:

docker/registry:2.4.1
docker/rethinkdb:1.0.0
docker/swarm:1.0.0

输出应该是:

docker/registry:2.4.2
docker/rethinkdb:latest

换句话说,File1 中不存在于 File2 中的每一行都应该成为输出的一部分。

我已尝试执行以下操作,但不起作用。

diff File1.txt File2.txt

最佳答案

您可以使用 grep 来实现:

$ grep -v -f file2.txt file1.txt
docker/registry:2.4.2
docker/rethinkdb:latest

如果文件中有很多行,我可能会使用 @user000001 解决方案。

关于linux - 获取一个文件中不存在于另一个文件中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39807078/

相关文章:

objective-c - 在 Objective-C 中编写一个命令行工具,它接受输入、清除屏幕然后输出

git - 如何在 oh-my-zsh 中使用 posh-git-bash?

linux - 检查shell脚本得到什么样的参数

linux - .txt文件搜索并输出

linux - 如何从另一个用户的另一个 shell 脚本调用 shell 脚本?

linux遍历目录中的文件

c - 从 bash 运行时,for 循环在 c 文件中被跳过

linux - 使用 Linux::TunTap 读取数据包

c++ - 使用管道从 STDIN 读取 fork 进程时出现问题

bash - 命令作为 Ubuntu 的 ZSH 中的窗口名称