Friday, October 10

difference

At work the other day, looking for a more human-friendly diff format*, I stumbled upon GNU wdiff, a wrapper around diff(1) which produces simple "these words added, these words deleted" output.

For example, let us imagine that I have two text files, one and two:

one two

Here is some text.

I will soon change it.

Here is some text.

I have changed it.

wdiff one two then produces:

Here is some text.

I [-will soon change-] {+have changed+} it.

Or maybe you're looking for something to display on the web. wdiff -w '<del>' -x '</del>' -y '<ins>' -z '</ins>' one two gives us:

Here is some text.

I will soon change have changed it.

This is pretty neat. For the sake of contrast, we might otherwise be looking at something like this:

--- one 2008-10-10 09:36:32.000000000 -0600
+++ two 2008-10-10 09:36:46.000000000 -0600
@@ -1,3 +1,3 @@
 Here is some text.
  
  -I will soon change it.
  +I have changed it.

While this is certainly information rich, it is exactly the kind of output that makes normal people go all glassy-eyed.