微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

比较多个文件中的列值

如何解决比较多个文件中的列值

我有 2 个包含以下内容文件。两个文件中 column1 的值始终匹配且按顺序排列。第 2 列的值是我必须比较的值。以下是这两个文件的示例。我是脚本新手,谁能帮忙。

文件 1

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

文件 2

tbla,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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。