Shell比较文件

时间:2015-06-30 08:58:56

标签: shell command-line diff text-processing

这是我在名为file.txt的文件中的基线值:

us-east-1a m1.small 1
us-east-1c m1.small 1
us-east-1c m3.medium 1
us-east-1c m3.medium 1
us-east-1c t1.micro 1
us-east-1d m1.large 1
us-east-1d m1.medium 1
us-east-1e m3.medium 6

这是生成的新文件file2.txt

us-east-1a c3.large 1
us-east-1a m1.small 7
us-east-1a m3.medium 6
us-east-1c m1.small 1
us-east-1c m3.medium 6
us-east-1c t1.micro 1
us-east-1d m1.large 1
us-east-1d m1.medium 1
us-east-1d m3.large 1
us-east-1d t2.medium 1
us-east-1e m3.medium 23

我在重构我想要的输出。我可以得到如下的确切输出。

us-east-1a c3.large 1
us-east-1a m3.medium 6
us-east-1d m3.large 1
us-east-1d t2.medium 1

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您希望比较前两个字段,如果它们不同,则应打印该行:

printf("the pointer is %p\n", (void *) &("x"['x']));

在数组中读取第一个文件awk 'FNR==NR{a[$1$2];next}!($1$2 in a)' file.txt file2.txt 。当处理第二个文件时,将比较数组内容。