Shell 比较文件
Shell comparing files
这是我在名为 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
如果我没理解错的话,您需要比较前两个字段,如果它们不同,则应打印该行:
awk 'FNR==NR{a[];next}!( in a)' file.txt file2.txt
读取数组中的第一个文件file.txt
。当处理第二个文件时,比较数组内容。
这是我在名为 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
如果我没理解错的话,您需要比较前两个字段,如果它们不同,则应打印该行:
awk 'FNR==NR{a[];next}!( in a)' file.txt file2.txt
读取数组中的第一个文件file.txt
。当处理第二个文件时,比较数组内容。