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 yesterday’s 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 today’s report after comparing with yesterday’s 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-2
however this new logic has been getting failed for below fields combination,
file-New
7! 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-Old
7! 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-Old
this command is unnecessarily printing the lines
8! J9BB-50! LHW! 22!
7! test3! test3! 8!
7! J9AA-50! LHR! 34!
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!
Without lines 2, 3 & 5 from the current result
we have to print the updated File-Old fields(for $2 check modified $4) those are updated in today’s 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?
diff
) ?FNR
as an array subscript. While reading the second file, you only use two array subscripts. As a result, entries from the first file are not considered.comm
utility which can print lines only in file1, only in file2 or in both.comm
utility requires files that are sorted in ascending order according to its current locale