比较多个文件中的列值



我有两个文件,内容如下。两个文件中column1的值始终匹配且顺序正确。第2列的值是我必须比较的。以下是两个文件的示例。我是一个脚本新手,任何人都能帮上忙吗。

文件1

tbla,2020-07-01
tblb,2020-08-12
tblc,2019-01-01
tbld,2016-02-27

FILE2

tbla,2020-07-01
tblb,2020-08-11
tblc,2019-01-02
tbld,2016-02-27

所需输出

tbla date matches in both the files 2020-07-01
tblb date mismatch found in files 2020-08-12 in file 1 and 2020-08-11 in file 2
tblc date mismatch found in files 2019-01-01 in file 1 and 2019-01-02 in file 2
tbld date matches in both the files 2016-02-27

我在下面试过了,但不起作用

$ awk -F't' 'NR==FNR{c[$1$2]++;next};c[$1$2] > 0' file2 file1

请尝试以下awk命令:

awk -F ',' 'NR==FNR{array[NR]=$2;next} {if (array[FNR]==$2) {print $1 " date matches in both the files " $2} else {print $1 " date mismatch found in files " array[FNR] " in file 1 and " $2 " in file 2"}}' file1 file2

相关内容

  • 没有找到相关文章

最新更新