0

When I compare the below 2 files its comparing it wrongly. How to compare? All the rows are available in the file2 but its not working. When I do a "vim -d a b" its showing like the values are missing in file2.

File1:

BILLINGS TEST,0211,TBN Enlace,Cable Company,11429,Digital,2SDV,EIA158,58,256 QAM,158,999.000,Billings -
BILLINGS TEST,0212,ATRES SD,Cable Company,25733,Digital,2SDV,EIA158,59,256 QAM,158,999.000,DEC 16
BILLINGS TEST,0213,Fox Life,Cable Company,50854,Digital,2SDV,EIA158,60,256 QAM,158,999.000,Billings -
BILLINGS TEST,0214,Sorpresa,Cable Company,8777,Digital,2SDV,EIA158,61,256 QAM,158,999.000,Billings - AD
BILLINGS TEST,0215,Baby TV SAP,Cable Company,16036,Digital,2SDV,EIA158,62,256 QAM,158,999.000,Billings
BILLINGS TEST,0216,Semillitas,Cable Company,19867,Digital,2SDV,EIA158,63,256 QAM,158,999.000,Billings - AD
BILLINGS TEST,0217,Latele Novela,Cable Company,13353,Digital,2SDV,EIA158,64,256 QAM,158,999.000,Billings -
BILLINGS TEST,0218,CINE MEXICANO,Cable Company,12675,Digital,2SDV,EIA158,65,256 QAM,158,999.000,Billings -

File2:

BILLINGS TEST,0211,TBN Enlace,Cable Company,11429,Digital,2SDV,EIA158,58,256 QAM,158,999.000,CLMS Billings
BILLINGS TEST,0213,Fox Life,Cable Company,50854,Digital,2SDV,EIA158,60,256 QAM,158,999.000,CLMS Billings
BILLINGS TEST,0214,Sorpresa,Cable Company,8777,Digital,2SDV,EIA158,61,256 QAM,158,999.000,CLMS Billings Test,0903,0041,MT_DSG_Plant
BILLINGS TEST,0215,Baby TV SAP,Cable Company,16036,Digital,2SDV,EIA158,62,256 QAM,158,999.000,CLMS
BILLINGS TEST,0216,Semillitas,Cable Company,19867,Digital,2SDV,EIA158,63,256 QAM,158,999.000,CLMS Billings Test,0903,0041,MT_DSG_Plant
BILLINGS TEST,0217,Latele Novela,Cable Company,13353,Digital,Big Timber -
BILLINGS TEST,0218,CINE MEXICANO,Cable Company,12675,Digital,bozapx03 - AD,EIA006,3,256
BILLINGS TEST,0219,DE PELICULA,Cable Company,50197,Digital,grfapx01 - AD,EIA006,5,256
BILLINGS TEST,0220,DE PELICULA CLASSICOS,Cable Company,50596,Digital,havapx01 -

enter image description here

  • Please help us help you by asking questions that are easy to read. But first of all, you should try to solve your problem yourself by experimenting with it. Does the problem occur only when all lines in both files are identical through the first 16 characters? If not, then give us sample data that differ in the first character or two. Does the problem occur only when you have lines that are over 100 characters long? If not, then give us sample data that has short lines.  … (Cont’d) – Scott Apr 1 '17 at 19:48
  • (Cont’d) …  Does the problem occur only when the files are nearly 10 lines long?  If not, then give us sample data with shorter files. Does the problem occur only when non-matching lines are very similar?  If not, then give us sample data where the lines that are different are so different that you can tell that they are different with a glance (i.e., don’t have BILLINGS TEST,02, Digital,2SDV,EIA158 and 256 QAM,158,999.000 on non-matching lines). My point is, you’ve given us data that are very confusing, forcing people to work hard to understand the patterns that are present. – Scott Apr 1 '17 at 19:48
4

The data is clearly not the same in the two files. If you look at the first line flagged up as different, there is a difference.

File 1 contains this line where File 2 does not:

BILLINGS TEST,0212,ATRES SD,Cable Company,25733,Digital,2SDV,EIA158,59,256 QAM,158,999.0

Even if you fix that, later lines are different.

I really don't see why you're puzzled that vimdiff is showing differences between two files that are different. Perhaps you need to update your question explaining more clearly what the issue really is?

Commands that may help are sort, comm, and possibly diff.

1

vim is doing what i would expect as the lines have​ moved around. Side-by-side, this is correct.

0

vimdiff seems to be somewhat smarter than diff, but it’s not as smart as a person.  Where it finds lines in file1 that are exactly identical to lines in file2, it treats those as being matching lines.  After a matching line, it compares sequential lines from the two files on a pairwise basis without looking to see if any lines in file1 that are similar to lines in file2.  In other words, when it gets out of sync, it doesn’t resync until it finds line(s) in file1 that are exactly identical to line(s) in file2.

As roaima pointed out, your File2 is missing the 0212 line.  Therefore, vimdiff gets out of sync at that point.  And since there are no identical lines after that, it never gets back into sync.  But even roaima seemed to miss the fact that, if you insert a 0212 line into File2 (even if it’s a dummy one), vimdiff stays in sync and does this:

vimdiff screen shot

Is this what you wanted?

-1

Try using meld to compare two files

  • Could you give an example ? – DarkHeart Mar 31 '17 at 1:28
  • I support your proposal, meld is good software and can be embeded into git. – utopic eexpress Mar 31 '17 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.