我有两个这样的 csv 文件;
422174,XN,20.99,2020-09-01,2022-01-20 20:20:28.613+00
421348,SB,21.99,2021-01-26,2022-01-20 20:20:28.613+00
885176,XN,41.80,2021-11-17,2022-01-20 20:20:28.613+00
881751,SB,12.81,2020-09-01,2022-01-20 20:20:28.613+00
722483,XN,67.50,2020-09-01,2022-01-20 20:20:28.613+00
第二个文件;
667843,XN,22.99,2020-09-01,2022-01-20 20:20:28.613+00
421348,SB,21.99,2021-01-26,2022-01-20 20:20:28.613+00
885176,XN,41.80,2021-11-17,2022-01-20 20:20:28.613+00
881751,SB,12.81,2020-09-01,2022-01-20 20:20:28.613+00
156734,XN,34.50,2020-09-01,2022-01-20 20:20:28.613+00
输出应该是;
667843,XN,22.99,2020-09-01,2022-01-20 20:20:28.613+00
156734,XN,34.50,2020-09-01,2022-01-20 20:20:28.613+00
我怎样才能使用 awk 来做到这一点?
答案1
我会使用comm
而不是awk
执行此任务:
comm -13 <(sort first.csv) <(sort second.csv) > difference.csv
从comm --help
:
-1 抑制列 1(FILE1 特有的行)
-2 抑制第 2 列(FILE2 特有的行)
-3 抑制第 3 列(两个文件中都出现的行)