Axel Beckert: Useful but Unknown Unix Tools: How wdiff and colordiff help to choose the right Swiss Army Knife
In light of the fact that it seems possible to fit the plastic caps of
a Debian branded Swiss Army Knife (Last orders
today!) on an existing Swiss Army Knife (German written
howto as PDF), I started to think about which Victorinox Cybertool
would be the best fitting for me.
And because the Victorinox comparison page doesn t really show diffs, just
columns with floating text which are not very helpful for generating
diffs in your head, I used command line tools for that purpose:
wdiff
Because the floating texts are not line- but just whitespace-based,
the tool of choice is not diff but wdiff, a word-based diff. It encloses additions and removals
in + + and [- -] blocks.
(No, those aren t Japanese smileys although they look a lot like some.
^^).
The easiest and clearest way is to copy and paste the texts from Victorinox comparison page into some text files and
compare them with wdiff:
$ wdiff cybertool34.txt cybertool41.txtSo this already extracted the information which are the seven tools which are in the Cybertool 41, but not in the Cybertool 34. Nevertheless the diff is still not easily recognizable on the first glance. There are several ways to help here. First
+Schraubendreher 2.5mm,+ Pinzette, N hahle mit Nadel hr, +Holzs ge,+ Bit-Schl ssel( 5 mm Innensechskant f r die D-SUB Steckverbinder, 4 mm Innensechskant f r Bits, Bit Phillips 0, Bit Phillips 1, Bit-Schlitzschrauben 4 mm, Bit Phillips 2, Bit Hex 4 mm, Bit Torx 8, Bit Torx 10, Bit Torx 15 ), Kombizange( H lsenpresser, Drahtschneider ), Stech-Bohrahle, Kugelschreiber( auch zum DIP-Switch verstellen ), Mehrzweckhaken (Pakettr ger), +Metalls ge( Metallfeile, Nagelfeile, Nagelreiniger ),+ Dosen ffner( kleiner Schraubendreher ), Kleine Klinge, Grosse Klinge, Ring, inox, Mini-Schraubendreher, Kapselheber( Schraubendreher, Drahtabisolierer ), +Holzmeissel / Schaber,+ Bit-Halter, Stecknadel, inox, Schere, Korkenzieher, Zahnstocher
wdiff has an option --no-common (the
according short option is -3) which just shows added and
removed words:
$ wdiff -3 cybertool34.txt cybertool41.txt ====================================================================== +Schraubendreher 2.5mm,+ ====================================================================== +Holzs ge,+ ====================================================================== +Metalls ge( Metallfeile, Nagelfeile, Nagelreiniger ),+ ====================================================================== +Holzmeissel / Schaber,+ ======================================================================This is already way better to quickly recognize the actual differences. But if you still also want to see the common tools of the two knifes you need some visual help: One option is to use
wdiff s --terminal (or
short -t) option. Added words are then displayed inverse
and removed words are shown underlined (background and foreground
colors hardcoded as there is no invert colors style in CSS or HTML):
But some still like to to use color instead of the contrast-rich inverse and the easily to oversee underlining. This is where colordiff comes into play: colordiff colordiff is like syntax highlighting for diffs on the command line. I works with classic and unified diffs as well as with wdiffs and debdiffs (the$ wdiff -t cybertool34.txt cybertool41.txt
Schraubendreher 2.5mm, Pinzette, N hahle mit Nadel hr, Holzs ge, Bit-Schl ssel( 5 mm Innensechskant f r die D-SUB Steckverbinder, 4 mm Innensechskant f r Bits, Bit Phillips 0, Bit Phillips 1, Bit-Schlitzschrauben 4 mm, Bit Phillips 2, Bit Hex 4 mm, Bit Torx 8, Bit Torx 10, Bit Torx 15 ), Kombizange( H lsenpresser, Drahtschneider ), Stech-Bohrahle, Kugelschreiber( auch zum DIP-Switch verstellen ), Mehrzweckhaken (Pakettr ger), Metalls ge( Metallfeile, Nagelfeile, Nagelreiniger ), Dosen ffner( kleiner Schraubendreher ), Kleine Klinge, Druckkugelschreiber, Grosse Klinge, Ring, inox, Mini-Schraubendreher, Kapselheber( Schraubendreher, Drahtabisolierer ), Holzmeissel / Schaber, Bit-Halter, Stecknadel, inox, Schere, Korkenzieher, Zahnstocher
debdiff command is part of the
devscripts package).
$ wdiff cybertool34.txt cybertool41.txt colordiff(Coloured Screenshots done with ANSI HTML Adapter from the package aha.) Some, especially those who are used to git, are probably confused by the default choice of diff colors. This is easily fixable by writing the following into you
+Schraubendreher 2.5mm,+ Pinzette, N hahle mit Nadel hr, +Holzs ge,+ Bit-Schl ssel( 5 mm Innensechskant f r die D-SUB Steckverbinder, 4 mm Innensechskant f r Bits, Bit Phillips 0, Bit Phillips 1, Bit-Schlitzschrauben 4 mm, Bit Phillips 2, Bit Hex 4 mm, Bit Torx 8, Bit Torx 10, Bit Torx 15 ), Kombizange( H lsenpresser, Drahtschneider ), Stech-Bohrahle, Kugelschreiber( auch zum DIP-Switch verstellen ), Mehrzweckhaken (Pakettr ger), +Metalls ge( Metallfeile, Nagelfeile, Nagelreiniger ),+ Dosen ffner( kleiner Schraubendreher ), Kleine Klinge, Grosse Klinge, Ring, inox, Mini-Schraubendreher, Kapselheber( Schraubendreher, Drahtabisolierer ), +Holzmeissel / Schaber,+ Bit-Halter, Stecknadel, inox, Schere, Korkenzieher, Zahnstocher $ wdiff cybertool29.txt cybertool41.txt colordiff
+Schraubendreher 2.5mm,+ Pinzette, N hahle mit Nadel hr, +Holzs ge,+ Bit-Schl ssel( 5 mm Innensechskant f r die D-SUB Steckverbinder, 4 mm Innensechskant f r Bits, Bit Phillips 0, Bit Phillips 1, Bit-Schlitzschrauben 4 mm, Bit Phillips 2, Bit Hex 4 mm, Bit Torx 8, Bit Torx 10, Bit Torx 15 ), +Kombizange( H lsenpresser, Drahtschneider ),+ Stech-Bohrahle, +Kugelschreiber( auch zum DIP-Switch verstellen ), Mehrzweckhaken (Pakettr ger), Metalls ge( Metallfeile, Nagelfeile, Nagelreiniger ),+ Dosen ffner( kleiner Schraubendreher ), Kleine Klinge, [-Druckkugelschreiber,-] Grosse Klinge, Ring, inox, Mini-Schraubendreher, Kapselheber( Schraubendreher, Drahtabisolierer ), +Holzmeissel / Schaber,+ Bit-Halter, Stecknadel, inox, +Schere,+ Korkenzieher, Zahnstocher
~/.colordiffrc:
newtext=green oldtext=red diffstuff=darkblue cvsstuff=darkyellow(See also
/etc/colordiff for the defaults and hints.)
colordiff has by the way two operating modes:
- Without parameter it reads diffs from standard input as seen above.
- With parameters it works as drop-in diff replacement including all diff options as shown below.
$ colordiff cybertool29-lines.txt cybertool34-lines.txt 12a13,14 > Kombizange( H lsenpresser > Drahtschneider ) 13a16,17 > Kugelschreiber( auch zum DIP-Switch verstellen ) > Mehrzweckhaken (Pakettr ger) 16d19 < Druckkugelschreiber 25a29 > SchereOr as unifed diff with some context:
$ colordiff -u cybertool29-lines.txt cybertool34-lines.txt --- cybertool29-lines.txt 2011-08-31 20:55:37.195546238 +0200 +++ cybertool34-lines.txt 2011-08-31 20:55:11.667710504 +0200 @@ -10,10 +10,13 @@ Bit Torx 8 Bit Torx 10 Bit Torx 15 ) +Kombizange( H lsenpresser +Drahtschneider ) Stech-Bohrahle +Kugelschreiber( auch zum DIP-Switch verstellen ) +Mehrzweckhaken (Pakettr ger) Dosen ffner( kleiner Schraubendreher ) Kleine Klinge -Druckkugelschreiber Grosse Klinge Ring inox @@ -23,5 +26,6 @@ Bit-Halter Stecknadel inox +Schere Korkenzieher ZahnstocherSo if you want nicely colored diffs with Subversion like you re used to with git, you can use
svn diff colordiff.
Just this morning, I was setting up TLS on a LDAP host, but
AltOS 1.0 TeleMini support and a host of new features
Bdale and I are pleased to announce the release of






What do you think of it?









In the 
I stopped my story in early 1994, after my Big Switch to the
mysterious and new world of Linux.
My home server, kheops, is now running Debian and is fed with news and
mail by FrMug, formerly French Minix Users Group and now run by AFAU,
the "Association Fran aise des Amateurs de Usenet".
As I'm still console-challenged, I'm reading mail and news on another
machine I have at home, named "khephren", which is running an, ahem,
beta copy of Microsoft Windows 95. Yeah, I know...:-)
These 1994-1999 years were mostly the Usenet years, for me. I
gradually became more and more involved in several fr.* newsgroups,
either related to the Linux world...or to the Windows world. The
latter was professionnally a bonus for me as 1994 is also the year
where I switched from the Material Science department at Onera to the
Network and Computing Department. My mission there was to accompany
the increasing prevalence of personal desktop workstations in the
daily life of what was formerly the Big Castle of Computing at Onera,
hosting various generations of Cray computers, most of which being in
the Top500 world supercomputers (we even had one in the Top10, very
briefly, at somepoint).
So, I was "the PC and Windows guy" in this world of supercomputing,
Unix and network wizards. But my hobby at home helped me keeping and
growing skills in both "worlds" which, over the years, has proven to
be a not so common profile..:-)
Meanwhile, at home, I was spending hours and nights reading those
newsgroups...or getting involved in fr.* hierarchy management..or
expanding my friends network to many people in the news, Linux, BSD
worlds.
That lasted for about 3 years with ups and downs (with three young
kids at home, you end up having slightly less time...). I was
gradually improving my home server use, adding more functionalities to
it, for instance setting it up as a file and print server with Samba
1.9.something (this will be the beginning of a long story with
samba!).
Unfortunately, my dear Ren