FILE Comaprison

Is it possible to comapre 2 files bit by bit and output the following things:

  1. Bit position of mismatch in each line
  2. Missing records in either of the two files

Note 3rd column in both the files is unique

File 1

ABC 1212 san
ASB 2121 van
AWS 2122 man
AKS 1112 dan
AQZ 1123 ran
SQA 3232 jam
BQA 3121 pan
GAT 3452 wat

File 2

ABC 1212 san
ASB 2222 van
AWS 2122 man
AQZ 1123 ran
AQZ 1123 wat
DAT 3223 sat
SQA 3232 jam
BQA 3121 pan
GAT 3452 wat

Output File

Records missing in file 1 are: DAT 3223 sat, AQZ 1123 wat
Records missing in file 2 are: AKS 1112 dan
Mismatch in bit position: 6 & 8 for string van

Please help in this regard

The diff and comm commands are probably your best bet. See "man diff" and "man comm".

Also, "cmp" can be useful as well.

Yes Glenn i have tried that but how to get exact bit postion from the output of diff.
I have been trying to solve this since yesterday but could not make through it as i am new to shell scripting i am facing lots of problems.
Is there any way to locate the exact bit position of mismactch within a line?

Please help in this regard

Thanks
Sandeep

From the man page for cmp:

cmp recognizes the following options:

 -l      Print the byte number \(decimal\) and the differing bytes
         \(octal\) for each difference \(byte numbering begins at 1
         rather than 0\).

Would that be what you need?


awk '{print $1,$2}' file1 | sort > tmp1
awk '{print $1,$2}' file2 | sort > tmp2

# records  unique to file1
comm -1 tmp1 tmp2
#records unique to file2
comm -2 tmp1 tmp2

Thank you Glenn and Jim!!
That has solved my problem

Thanks & Regards
Sandeep

Hi Glenn

While using cmp i had a problem. If a bit postion value is missing in one file then after that missing bit postions all bits henceforth are mismatching.This results in outputing all the bit position and hence it becomes difficult to track.

Eg: I ran following command and ouput is also given

$ cmp -l 1.txt 2.txt
5 15 163
6 12 15
7 64 12
8 40 64
9 142 40
10 163 142
cmp: EOF on 1.txt

File 1.txt
4 as
4 bs

File 2.txt
4 ass
4 bss

Whereas the desired ouput is 5th byte in line 1 and 5th byte in line 2 (or 9th byte from start of file).
Is it possible to implement that?
Please help me in this regard