Hi All,
I have a requirement to compare data column which is the last field in two different files and trigger and alert if the difference is greater than 1 for each row.
File1
Jan Acount1 2014 11223
Feb Account2 2014 2345
Mar Account3 2014 1233
File2
Jan Account1 2014 11224
Feb Account2 2014 2345
Mar Account3 2014 1239
Can you please help. Thank you.
Hello Naresh Babu,
Welcome to forum, kindly use the code tags while using commands and codes in the posts please as per forum rules. Kindly go through the forum rules in following link.
Following may help you in same.
awk -vs1="\"" 'FNR==NR{A=$NF;$NF="";X[$0]=A;Q=FILENAME;next} {B=$NF;$NF=""} ($0 in X){if(B - X[$0] > 1){print FILENAME " column " s1 $0 B s1 " last column has grater value than last colum in " Q " for column " s1 $0 s1}}' File1 File2
Output will be as follows as per given input by you.
File2 column "Mar Account3 2014 1239" last column has grater value than last colum in File1 for column "Mar Account3 2014 "
EDIT: Just added a bit of code to get the complete columns which have differance more than 1 as follows.
awk -vs1="\"" 'FNR==NR{A=$NF;$NF="";X[$0]=A;Y[$0]=A;Q=FILENAME;next} {B=$NF;$NF=""} ($0 in X){if(B - X[$0] > 1){print FILENAME " column " s1 $0 B s1 " last column has grater value than last colum in " Q " for column " s1 $0 Y[$0] s1}}' File1 File2
Output will be as follows.
File2 column "Mar Account3 2014 1239" last column has grater value than last colum in File1 for column "Mar Account3 2014 1233"
Thanks,
R. Singh