Hi
The comm does a line by line compare. I am looking for a compare where each line (entry) from file 1 is compared with all the lines on the second file and whatever value is common on both files is displayed.
For example, file1 contains
3322
1212
1111
2222
4444
5555
4545
6666
and file 2 contains
9999
0000
4444
5555
7777
8888
The output should be
4444
5555
I found the following script after googling,
comm file1.txt file2.txt | awk -F'\t' '
{a[NF,++i[NF]]=$NF}
END{
print "Common\tFile1\tFile2"
for(j=1;j<=i[1]||j<=i[2]||j<=i[3];++j)
print a[3,j]"\t"a[1,j]"\t"a[2,j]
print "===\t===\t==="
print i[3]"\t"i[1]"\t"i[2]
}'
but the above script is giving the wrong output, not working for me. The output is as follows:
user@sysadmn ~
$ ./compare.sh
Common File1 File2
3322 9999
1212 0000
1111 4444
2222 5555
4444 7777
5555 8888
4545
6666
=== ==== ====
8 6
user@sysadmn ~
The desired output is:
user@sysadmn ~
$ ./compare.sh
Common File1 File2
4444 3322 9999
5555 1212 0000
1111 4444
2222 5555
4444 7777
5555 8888
4545
6666
=== === ===
8 6
user@sysadmn ~
Thanks in advance