我试图找出两个文件之间的区别,在其中我想知道file_2中的新条目。
如果a.txt包含:
a
b
cb.txt包含:
c
d
f我想要d and f
我使用的命令是:diff --changed-group-format="%>" --unchanged-group-format=''
mymach@dev-machine:~/test$ grep 'C:/Documents and Settings/pandep2/AppData/Local/Google/Chrome/User Data/CrashpadMetrics.pma~RF115cef5.TMP' file_1.log
C:/Documents and Settings/pandep2/AppData/Local/Google/Chrome/User Data/CrashpadMetrics.pma~RF115cef5.TMP
mymach@dev-machine:~/test$ grep 'C:/Documents and Settings/pandep2/AppData/Local/Google/Chrome/User Data/CrashpadMetrics.pma~RF115cef5.TMP' file_2.log
C:/Documents and Settings/pandep2/AppData/Local/Google/Chrome/User Data/CrashpadMetrics.pma~RF115cef5.TMP
mymach@dev-machine:~/test$ diff --changed-group-format="%>" --unchanged-group-format='' file_1.log file_2.log >diff_file.log
mymach@dev-machine:~/test$ grep 'C:/Documents and Settings/pandep2/AppData/Local/Google/Chrome/User Data/CrashpadMetrics.pma~RF115cef5.TMP' diff_file.log
C:/Documents and Settings/pandep2/AppData/Local/Google/Chrome/User Data/CrashpadMetrics.pma~RF115cef5.TMP既然两个文件中都存在相同的文件,那么为什么diff命令仍然要报告该文件呢?
发布于 2018-06-14 16:29:03
在这种情况下,我们最好在Unix中使用comm命令。
对于上述场景,我使用了:
comm -23 <(sort file_1.txt) <(sort file_2.txt)这将给出file_1.txt的唯一文件
comm -13 <(sort a.txt) <(sort b.txt)这将给出file_2.txt的唯一文件
comm -12 <(sort a.txt) <(sort b.txt)这将在两个文件之间提供公共文件。
https://stackoverflow.com/questions/50855999
复制相似问题