Awk easy script

  • Thread starter Thread starter sponge
  • Start date Start date
S

sponge

Hi,

probably this is too easy but i just started playing around with awk and can't figure this out. Say I have a file with these two lines each split in columns:

A S D M
A R W D

I want awk to print "right answer" if for example the third element in the first line matches the fourth element in the second line, as is the case for letter "D".

My attempt was:

awk '(NR == 1 && $3 == /D/) && (NR == 2 && $4 == /D/) {print "right answer"}' file.txt

But it is not working. Any suggestions?
Thanks!

Continue reading...
 
Back
Top