Hi all,
I have two large files and i want a field by field comparison for each record in it.
All fields are tab seperated.
file1:
Email SELVAKUMAR RAMACHANDRAN
Email SHILPA SAHU
Web NIYATI SONI
Web NIYATI SONI
Email VIINII DOSHI
Web RAJNISH KUMAR
Web SUMIT BHATI
Email MADHURA VAIDYA
Phone PRITI BANE
Web SHIVALI PATEL
Web SANDESH PAWAN
file2:
Email SELVAKUMAR RAMACHANDRAN
Email SHILPA SAHU
Web NIYATI SONI
Web NIYATI SONI
Email VIINII DOSHI
Web RAJNISH KUMAR
Web SUMIT BHATI
Email MADHAVI VAIDYA
Phone PRITI BANE
Web SHIVALI PATEL
Web SANDESH PAWAR
Output :
Record no.8 is different and the field is ( field no/field value)
Record no.11 is different and the field is ( field no/field value)
or
Record no.8,11 is different and the field is ( field no/field value) , ( field no/field value) respectively.
Will be thankful if the solution comes in AWK script.
Thanks,
Suman Singh
You want old value, new or both? There are never new lines?
Try this if you have gnu diff available.
diff -y indj indj2 | awk '/\|/ { print "Record no."NR " value "$0 }'
Both the values. both new and old one.
# ./justdoit file1 file2
Record no.8 is different and the field is ( field no 2 / field value MADHAVI ) in file2
Record no.11 is different and the field is ( field no 3 / field value PAWAR ) in file2
# ./justdoit file2 file1
Record no.8 is different and the field is ( field no 2 / field value MADHURA ) in file1
Record no.11 is different and the field is ( field no 3 / field value PAWAN ) in file1
# cat justdoit
#!/bin/bash
ix=0
while read -r linef
do
compar[ix]=$linef
((ix++))
done<$1
ix=0
while read -r lineff
do
comparr[ix]=$lineff
((ix++))
done<$2
x=0;ix=0;c=0
for i in "${compar[@]}"
do
((c++))
if [ "$i" != "${comparr[x]}" ] ; then
chk=(${compar[x]}) ; chk2=(${comparr[x]})
for j in ${chk[@]}
do
((fno++))
if [ "$j" != "${chk2[ix]}" ] ; then
echo "Record no.$c is different and the field is ( field no $fno / field value ${chk2[ix]} ) in $2"
fi
((ix++))
done
fi
((x++)) ; ix=0;fno=0
done
regards
ygemici