Hello,
I am practising awk and decided to compare two columns and print the result of the comparison as third column
i/p data
c1,c2,c3
1,a,b
1,b,b
i am trying to compare the last two columns and if they match I am trying to print match
else mismatch
(Ideally i want that as a last column in the same file
#!/bin/bash
IFS="," while read -r $line
a=awk '{print $1, ($NF=$(NF-1))?"match":"mismatch"}'<filename.txt
awk -v var=$a '{BEGIN s=a}{print $0,s}
'
expected output
c1,c2,c3,c4
1,a,b,mismatch
1,b,b,match
but all I am getting is
c1,c2,c3
1,a,b
1,b,b
or if just say awk'{print $NF}
I am getting the output as
c1,c2,c3
1,a,b
1,b,b
same out put even if i use $(NF-1)
I also tried commenting the
awk -v var=$a '{BEGIN s=a}{print $0,s}
line in my code and ran it
#!/bin/bash
IFS="," while read -r $line
awk '{print $1, ($NF=$(NF-1))?"match":"mismatch"}'<filename.txt
#awk -v var=$a '{BEGIN s=a}{print $0,s}
'
the output i get is
c1,c2,c3,match
1,a,b,match
1,b,b,match
But i Read $NF
returns the last column and NF-1
returns the last but one column.
Please advice where my thinking is wrong.
Thanks.