FILE Comaprison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FILE Comaprison
# 1  
Old 06-09-2006
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

Last edited by sandeep_hi; 06-09-2006 at 11:35 AM..
# 2  
Old 06-09-2006
The diff and comm commands are probably your best bet. See "man diff" and "man comm".

Also, "cmp" can be useful as well.
# 3  
Old 06-09-2006
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
# 4  
Old 06-09-2006
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?
# 5  
Old 06-09-2006
Code:
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

# 6  
Old 06-12-2006
Thank you Glenn and Jim!!
That has solved my problem

Thanks & Regards
Sandeep
# 7  
Old 06-12-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies
Login or Register to Ask a Question