views:

528

answers:

4

Hi everyone,

I'd like to use 'diff' to get a both line difference between and character difference. For example, consider:

File 1

abcde
abc
abcccd

File 2

abcde
ab
abccc

Using diff -u I get:

@@ -1,3 +1,3 @@
 abcde
-abc
-abcccd
\ No newline at end of file
+ab
+abccc
\ No newline at end of file

However, it only shows me that were changes in these lines. What I'd like to see is something like:

@@ -1,3 +1,3 @@
 abcde
-ab<ins>c</ins>
-abccc<ins>d</ins>
\ No newline at end of file
+ab
+abccc
\ No newline at end of file

You get my drift.

Now, I know I can use other engines to mark/check the difference on a specific line. But I'd rather use one tool that does all of it.

Any ideas?

Thanks!

A: 

Python's difflib can do this.

The documentation includes an example command-line program for you.

The exact format is not as you specified, but it would be straightforward to either parse the ndiff-style output or to modify the example program to generate your notation.

Will
Thanks! I'll look into it. I was hoping for a something more standardized (like a hidden command line argument). But it might do fine still.I'll look into python if no one has anything more standard (though it seems like not).
VitalyB
A: 

Python's difflib is ace if you want to do this programmatically. For interactive use, I use vim's diff mode (easy enough to use: just invoke vim with vimdiff a b). I also occaisionally use Beyond Compare, which does pretty much everything you could hope for from a diff tool.

I haven't see any command line tool which does this usefully, but as Will notes, the difflib example code might help.

Ned
Oh.. I was hoping for a something more standardized (like a hidden command line argument). The damnest thing is that I have Beyond Compare 2 and it even supports text output to file/console of the diff but it still only includes line-diffs and not char-diffs.I'll look into python if no one has anything else.
VitalyB
+2  A: 

I didn't check the python library but eventually found Google's solution good enough for what I needed. And it is implemented in so many languages. I was impressed.

VitalyB
A: 
use cmp command in solaris

 cmp

Compare two files, and if they differ, tells the first byte and line number where they differ.
Venkataramesh Kommoju