Hi,
I want to compare 2 files and get a new output that will contain the differences. Each file contain 5 fields (matricule, first name, last name, age, profession)
file1 is the original file. file2 should be synchronized with file1:I want to look for any change on file1 and want to apply these changes on file2.
#cat file1
10000;john;Trad;40;teacher
10001;georges;Hold;34;physician
10002;Catherina;Rick;36;doctor
10003;marc;bob;46;techician
#cat file2
10000;john;Trad;40;teacher
10001;georges;Hold;40;physician
10003;marc;Robert;46;programmer
10004;Maria;Roch;39;nurse
I us this script:
awk 'NR==FNR {f1[$0]=$0}
NR!=FNR {f2[$0]=$0}
END {
for(i in f1) if(!(i in f2)) print "Only in f1: " f1
[i]for(i in f2) if(!(i in f1)) print "Only in f2: " f2
[i]}' file1 file2
I get this result:
==============
Only in f1: 10001;georges;Hold;34;physician
Only in f1: 10003;marc;bob;46;techician
Only in f1: 10002;Catherina;Rick;36;doctor
Only in f2: 10004;Maria;Roch;39;nurse
Only in f2: 10003;marc;Robert;46;programmer
Only in f2: 10001;georges;Hold;40;physician
But it is not what I hope to get and obtain as result.
I want to get a result like that:
matricule:10001
change: modified
age:40
matricule:10002
change: deleted
matricule:10003
change: modified
lastname: Robert
profession: programmer
matricule:10004
change: added
firstname:Maria
lastaname:Roch
age:39
profession:nurse
Can someone help me to get this result with awk?
Thanks,
Imad77