0

This is my baseline values in a file named 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

This is the new file generated 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

I am reframing my desired output . Can I get the exact output like below.

us-east-1a c3.large 1
us-east-1a m3.medium 6
us-east-1d m3.large 1
us-east-1d t2.medium 1
chaos
  • 8,162
  • 3
  • 33
  • 40
  • 2
    Yes this is possible. – Martin Jun 30 '15 at 09:00
  • Hey martin thanks could you help me with sample script. – user3415790 Jun 30 '15 at 09:01
  • I tried using temp=0; while read line do echo $line > temp1.txt while read line2 do echo $line2 > temp2.txt diff temp1.txt temp2.txt > temp3.txt compare=`cat temp3.txt | wc -l | head -1` if [ "$compare" -eq 0 ]; then temp=1; fi done < file2.txt if [ "$temp" -eq 1 ]; then cat $line2 fi done < file1.txt – user3415790 Jun 30 '15 at 09:02

1 Answers1

1

If I understood correctly, you want the first two fields compared and if they differ the line should be printed:

awk 'FNR==NR{a[$1$2];next}!($1$2 in a)' file.txt file2.txt

The first file file.txt is read in an array. And when the second file is processed the array contents are compared.

chaos
  • 8,162
  • 3
  • 33
  • 40