diff is a fabulous tool. Most of the time it is used to compare files. in this case we are going to use it to compare the output of two commands.
For a simple example, I have two directories of images, the file names are the same. The directory
./big has larger versions of the images, where as
./medium has medium sized versions for use on the web. Some of the images may be missing from the directories. Maybe the person converting them added a letter ‘s’ to the end of a file name inadvertently? But which ones?
well we could use
ls. I’ll show my entire command line here:
jonny@taft:~/Desktop/images$ ls ./*
this is the output
air.jpg barrels.jpg garbage.jpg photo.jpg smoke.jpg
autos.jpg beam.jpg jordan.jpg plane.jpg turm.jpg
balloon.jpg crack.jpg mouth.jpg rubble.jpg utopia.jpg
air.jpg beams.jpg detailTwo.jpg jordan.jpg rubble.jpg
autos.jpg canada.jpg garbage.jpg mouth.jpg smoke.jpg
balloon.jpg crack.jpg hillary.jpg photo.jpg turm.jpg
barrels.jpg detailOne.jpg identity.jpg plane.jpg utopia.jpg
I could compare the list of files visually, but I say “let robots’ brains do robots’ work”
This would be the cool way (which is the way the cool kids are doing things) to do the same job:
diff <(ls ./big) <(ls ./medium)
and here is what that looks like:
I think too many times, I miss items, or see things that aren't there when I'm comparing lists visually. Robots are harder to trick at jobs like comparing lists or counting.
... a dba thought I should be able to compare long lists of numbers visually. Since I was a programmer after all, I should have that ability right?? Personally I don't think the task of comparing long strings of numbers visually should be required of a programmer analyst/dba. I like results that I can test with a machine. Robots' brains are for robots' work, people brains are for thinking creatively within a framework of good methods, to solve interesting problems.
as usual ... here is a page with some useful tips including a version of the one above.