diff - 重击 : comm (or similar) when compare multiple files

标签 diff comm

我遇到以下问题:我想比较包含这样的列表的 8 个文件的内容

Sample1.txt    Sample2.txt     Sample3.txt
apple          pineapple       apple
pineapple      apple           pineapple
bananas        bananas         bananas
orange         orange          mango
grape          nuts            nuts

使用comm Sample1.txt Sample 2.txt我可以有这样的东西

grape    nuts    apple
                 pineapple
                 bananas
                 orange

这意味着在第一列中我有一些仅与第一个样本相关的内容,第二列中的内容仅与第二个样本相关,第三列中的内容是共同的。

我想做同样的事情,但有 8 个文件(示例)。对于 diff 这是不可能的,但最后我想有

Sample1  Sample2   Sample3    ...Sample8     Things in common
grape    nuts      mango                     apple
                                             pineapple
                                             bananas

有机会用 bash 来做吗?是否有像 diff 这样的命令允许搜索两个以上文件的差异?

谢谢大家...我知道这是一个具有挑战性的问题

法比奥

最佳答案

这是我的天真的解决方案:

first=sample1.txt; for a in *.txt; do comm -12 $first $a >temp_$a; echo "comparing" $first " " $a "and writing to temp_$a"; first=temp_$a; cat temp_$a; done;

关于diff - 重击 : comm (or similar) when compare multiple files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15724933/

相关文章:

unique - 查找两个文件之间的唯一行

linux - linux "comm"工具比较文件时如何显示行号

Windows命令仅打印两个或多个文件中的公共(public)行

bash - 比较两个 greps 的输出

sql-server - SQL Server 差异工具

Git apply 不创建新文件?

merge - 将派生代码快照与更新的上游代码合并的最佳实践工具和技术?

windows - Windows 7 上 Sourcetree 中的 Diff Word docx 文件

python - git-diff 如何生成大块描述?

bash - 删除文件 A 中包含文件 B 中字符串的所有行