we have to print the old entries only Delta(Difference) in File-1 and File-2. newly added enties in files-1 no need to print.on my unix server everyday new report is extracted from system which is later on compared with yesterdays report. The newly added lines in Current day report are printed by separate logic, which works perfectly.Now My requirement is to identify the fields(for $2 check modified $4) those are updated in todays report after comparing with yesterdays report. So logic should run to check $2 line by line to find out $4 updated fields from File1 and print the same.I have NR=FNR logic to do so, but its not working for below case/usr/xpg4/bin/awk -F'!' 'NR==FNR{++a[$2,$4];next} !a[$2,$4]++ || NR==FNR{++a[$4];hold} a[$4]++' file-1 file-2however this new logic has been getting failed for below fields combination,file-New7! J9AA-50! LHR! 35!7! J9AA-50! LHR! 34!8! J9BB-50! LHW! 22!8! J9BB-50! LHW! 22!7! test3! test3! 8!7! test3! test3! 8!7! JWZZ-50! LHN! 15!7! J9AA-50! LHR! 34!8! J9BB-50! LHW! 21!File-Old7! J9AA-50! LHR! 34!7! J9AA-50! LHR! 34!8! J9BB-50! LHW! 22!8! J9BB-50! LHW! 22!7! test3! test3! 8!7! test3! test3! 8!7! JWZZ-50! LHN! 14!7! J9AA-50! LHR! 34!8! J9BB-50! LHW! 21!with new command for compare and print. below logic fail to print expected result,/usr/xpg4/bin/awk -F'!' 'NR==FNR{++a[$2,$4];next} !a[$2,$4]++ || NR==FNR{++a[$4];hold} a[$4]++' File-New File-Oldthis command is unnecessarily printing the lines 7! J9AA-50! LHR! 34! , 8! J9BB-50! LHW! 22! & 7! test3! test3! 8!Current Result,7! J9AA-50! LHR! 34!8! J9BB-50! LHW! 22!7! test3! test3! 8!7! JWZZ-50! LHN! 14! 7! J9AA-50! LHR! 34!Expected Result:7! J9AA-50! LHR! 34!7! JWZZ-50! LHN! 14!we have to print the updated File-Old fields(for $2 check modified $4) those are updated in todays new report. so The logic has to become search $2 from File-Old in File-new if $2 was present in File-New then compared respective $4 values, if $4 is updated then print that line of File-Old.can anyone please suggest the changes/new logic to get Expected output. if its not possible by using NR=FNR then how can we get it by using shell/perl script?
how to print only Difference in two files using NR=FNR?
shell;awk;perl