2个文件,匹配列并从2列中减去

时间:2019-05-16 12:54:48

标签: awk

我有2个文件,我想做一些减法。

文件1

device1 IF-MIB::ifInErrors.10023 = 102030
device2 IF-MIB::ifInErrors.10026 = 1450

文件2

device1 IF-MIB::ifInErrors.10023 = 102034
device2 IF-MIB::ifInErrors.10026 = 1460

所需的输出

device1 IF-MIB::ifInErrors.10023 = 4
device2 IF-MIB::ifInErrors.10026 = 10

尝试了一些awk示例,我得到的只是1个

join file1 file2 | awk '{print $1, $7-$5}' > test

1 个答案:

答案 0 :(得分:1)

尝试一下:

join -t= file1 file2 | awk -F'=' '{print $1 "= " $3-$2}' > test

我用=作为连接和awk的分隔符

相关问题