There are three functions I use all the time as a programmer. I need to find files with a particular name on my drives. I need to find out which files contain a particular word or phrase. I need to compare two different versions of the same files and see what those differences are. I also spend a lot of time at the command line. The first function can easily be performed on Windows using dir /s. The second function can be handled by any grep program and there are several versions available for Windows that can easily be downloaded from the Internet. The third function, I usually use the fc command. However, for files with very long lines it can be difficult to read the results and find the differences. It just so happened that I needed to compare several XML files with long lines and was having trouble using fc, so I went looking for Open Source alternatives. After trying every file difference tool I could find at Sourceforge, I came across a program that I’m thrilled to use. I now work with it all the time for comparing file differences. I even use it in place of fc for short files.
You may have heard of popular programs on Windows such as examdiff or winmerge. However, how many of you have heard of diffh? I like command line tools and you can definitely use this as a command line tool. However, you can also integrate it with an editor such as SciTE if you prefer to avoid the command line. It’s cross-platform. So, if you’re switching between Windows and Linux or FreeBSD or even a Mac, you can compile and build it on each machine and use the same program everywhere. Even though it’s a command line program, the output is more graphical, with highlighted text to show you the differences between the two files. How do you get that kind of output with a text program? The output is in HTML format, easily viewable by any good web browser.
If you’d like to try diffh for yourself, here are some tips for getting it to up and running on Windows. It doesn’t do the hard work of comparing the files. It relegates that to diff, a program that’s commonly available on most POSIX systems. What diffh does is take the output from a standard difference tool such as diff and create an attractive readout in web page format. So, to use diffh, you’ll need a copy of diff. Luckily, there are several available. Both MinGW and DJGPP projects include diff. I personally like the version that’s part of the GNUWin32 project at http://gnuwin32.sourceforge.net/pa install diffh. ckages/diffutils.htm. Once you have diff installed on your machine and a good web browser, you’re ready for diffh. Its location at Sourceforge is http://sourceforge.net/projects/diffh/. However, Sourceforge only has the source code. To run on Windows, you’ll need an executable. If you don’t want to compile and build it yourself, you can use the download available from this site. (See below.)
After everything’s properly installed, you’ll need to know how to run diffh. From the command line in the same directory as your diff and diffh programs, type the following:
diff -u file1 file2 | diffh > diff.html start diff.html
This will compare file1 with file2 using diff, run the output through diffh and store the results in the file diff.html. Then, start executes your default browser and lets you view the output diff.html. If you don’t have a default browser set or want to change the browser, you can change which application is mapped as a default to your html extension. You can also specify the browser you want to use in place of start. Make sure to give the names of the files you want to compare in place of file1 and file2. If diff and diffh aren’t in the same directory, you’ll need to specify where they are or add them to your environment path.
That’s a lot of typing. Another option is to create a batch file to remember all the commands. Then just type something similar to the following at a command line:
dodiff file1 file2
If you’d like some information on creating a batch file for diffh, I have an example available.
Ready to try out diffh on your own machine? Here’s the download…
You can download the diffh executable right here!
I used MinGW and msys to compile and build the application. I’ve also included a copy of the source code I used when I built it.
Diffh has quickly become one of my favorite and most often used tools on the PC. Try it out and see if you can come up with your own uses for it.
Last 5 posts by Winston Crutchfield
- Disney Kingdoms comics - July 7th, 2017
- Sonic the Hedgehog - June 19th, 2017
- He-Man / ThunderCats - June 5th, 2017
- Scooby Apocalypse - May 15th, 2017
- Wacky Raceland - May 1st, 2017