linux - 比较两个文件并将不匹配的数字写入新文件

标签 linux shell unix diff

我有两个文件,其中 ifile1.txt 是 ifile2.txt 的子集。

ifile1.txt   ifile2.txt
    2            2
    23           23
    43           33
    51           43
    76           50
    81           51
   100           72
                 76
                 81
                 89
                100

欲望输出

ofile.txt
   33
   50
   72
   89

我正在尝试

diff ifile1.txt ifile2.txt > ofile.txt

但它给出了不同的输出格式。

最佳答案

由于您的文件已排序,您可以使用 comm为此命令:

comm -1 -3 ifile1.txt ifile2.txt > ofile.txt

-1 表示省略第一个文件特有的行,-3 表示省略两个文件中的行,所以这只显示了行对第二个文件是唯一的。

关于linux - 比较两个文件并将不匹配的数字写入新文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31444394/

相关文章:

linux - 将最近更改的文件从一台(开发)服务器推送到远程(实时)服务器的脚本?

java - Netbeans(和其他 Java 应用程序)在 Linux 上运行缓慢

shell - awk: hping: 打印 icmp 发起/接收之间的差异

sockets - 我可以测试文件描述符的类型是否适合 read() 吗?

linux - 将存储库版本反转为旧版本的 Subversion

php - 如何在单个 shell 行中执行多个 PHP 文件?

regex - 使用 grep 访问文件中的单词

linux - 如何在 linux 中的 postscript 或 pdf 文件的每一页底部添加页脚?

Symfony Apache 2 : Unable to create the cache directory/var/cache

C++ 文件选择窗口