Dear Experts,
Have been seraching this forum from this morning for my query but dint find hence posting it her... Basically i have two input files BSS and MSS which has a unique string , hence i hav tried and seperated the text to compare frm both files .. Any my present input files look like below:
File1
40468006A2027
40468006A2028
40468006A2029
40468006A7577
40468006A7578
40468006A7579
File2
40468006A210D
40468006A210E
40468006A210F
40468006A7577
40468006A7578
40468006A7579
40468111222
40468abcabd
Here each line of file1 should be scanned with File2 , similarly vice versa and my output should be
Data Missing in File2 which exist in File1:
40468006A2027
40468006A2028
40468006A2029
Data Missing in File1 which is present in File2:
40468006A210D
40468006A210E
40468006A210F
40468111222
40468abcabd
Tried comm grep diff , nothing basically works as loop is required to search each value against all lines... Please help me in this regard
Thanks in Advance
awk 'BEGIN{print "Data Missing in "ARGV[1]" but present in "ARGV[2]}NR==FNR{a[$0]++}!($0 in a)' File1 File2
awk 'BEGIN{print "Data Missing in "ARGV[1]" but present in "ARGV[2]}NR==FNR{a[$0]++}!($0 in a)' File2 File1
Or with one command:
awk 'BEGIN{print "Data Missing in File1 which exist in File2: "}
NR==FNR{arr[$0]=$0; next}
$0 in arr {delete arr[$0]; next} {print}
END{print "Data Missing in File2 which is present in File1: "
for( i in arr ){print arr}}
' file1 file2
With a slightly different output:
comm -3 <(sort file1) <(sort file2)
Thanks for the response..
But both the codes giving just print of both files not the difference
Data Missing in File1 which exist in File2:
40468006A2027
40468006A2028
40468006A2029
40468006A7577
40468006A7578
40468006A7579
Data Missing in File2 which is present in File1:
40468abcabd
40468111222
40468006A210D
40468006A210E
40468006A210F
40468006A7577
40468006A7578
40468006A7579
Do you have a space in some lines at the end of the line? In that case you can try this:
awk 'BEGIN{print "Data Missing in File1 which exist in File2: "}
NR==FNR{arr[$1]=$1; next}
$1 in arr {delete arr[$1]; next} {print}
END{print "Data Missing in File2 which is present in File1: "
for( i in arr ){print arr}}
' file1 file2
I am really sorry.. One file had space hence difference was showing for all records as space also it was considering.. Now working fine... Thanks a lot
Data Missing in File1 which exist in File2:
40468006A2027
40468006A2028
40468006A2029
Data Missing in File2 which is present in File1:
40468abcabd
40468111222
40468006A210D
40468006A210E
40468006A210F