【发布时间】:2019-08-09 17:20:57
【问题描述】:
我需要根据主列逐列比较 2 个文件(它可以是 1 列或多列作为灵长类键)。它应该生成 3 个 csv 文件作为输出 - 差异,file1 中的额外记录,file2 中的额外记录
注意:尝试使用sdiff,但它没有提供所需的输出
例子:
这里第一列是主键
file1 :
abc 234 123
bcd 567 890
cde 678 789
file2 :
abc 234 012
bcd 532 890
cdf 678 789
Output files
differences file :
abc,234,123::012
bcd,567::532,890
extra records in file1 :
cde,678,789
extra records in file2
cdf,678,789
【问题讨论】:
-
检查
comm二进制文件,一个标准的unix命令行工具comm --help -
comm 将给出不匹配的记录,但不会突出显示差异在哪一列
-
您可以先将数据转换为“长格式”,详情查看R-tidyverse文档。