Computing: Computer Basics

Home and Office: Comparing the content of text files.


Comparing the content of 2 files with highlighting of all differences between the 2 texts may be very useful and helpful, in particular for programmers, who want to see what exactly they have modified from one development snapshot to another (especially, if the old version worked and the newer one aborts with a runtime error, that you can't find). But for home and office users, too, there may be cases, where they want to have a closer look at the content difference between 2 documents; these documents may be your own letters or memos, paragraphs of different books or parts of different websites, ... Please, note, that the files I'm speaking about here, are text files. Thus, if you want to compare 2 Word or Writer documents, first create 2 text files and use copy/paste to transfer the paragraphs to compare from your wordprocessor application to your text editor.

There are specialized applications to compare text files and, as with most software, you can find programs on the Internet, that are entirely free of costs. I had the need of one of those, when working on my animal database. In fact, I do all development on my local machine and then upload it to my site. Sometimes forgetting to make changes, that I made locally, to the site's database server, the 2 databases aren't always perfectly synchronized. So, I decided to export the table data (e.g. as .csv files) and then use a text file comparison tool to show me the differences, that might exist in the 2 datasets.

I tried out 3 free programs for MS Windows: AppDiff (v1.6.1.33; x86) and DiffMerge (v4.2.0; x64) both failed my expectations: they seemed not to correctly understand the encoding of the text, exported from the MySQL tables. Both applications are said to properly handle UTF-8 documents, but when looking at my files' content, umlauts and other characters with accents did not correctly be displayed. Thus, I tried WinMerge (v2.16; x86) and this time, I got what I wanted!

WinMerge may be freely downloaded from the WinMerge Homepage. I actually use version 2.16 (x86), running without any problems on my Windows 10 64bit.

Install the program, run it and click the "Open" icon. A dialogbox, where you can browse for the files to be compared (2 or 3 files) and set some general options telling the program how exactly comparison has to be done, pops up. Note, that you can open any of the files as read-only; this is a simple way to be sure not to modify a file, that you want to keep as is. Note, that if your files are actually archives, the application can unpack them as they are used.

WinMerge: Selecting the files to be compared

Beside comparing the files' content, WinMerge also allows simply comparing the file size and/or date. The "Binary content" compare method should also allow to compare non-text files.

The settings for the "Whitespaces" and "Case sensitive" options depend on how exactly you want your files to match. In the case of my development files, checking "Ignore carriage return differences" is mandatory (as the webserver files have been created by a Unix system).

The difference highlighting in WinMerge is not as sophisticated as in AppDiff or DiffMerge (that use more different color): all lines, that contain differences (different line content or lines existing in one file, but not in the other) are displayed with a yellow background. On the other side, as you can see on the screenshots with my Perl scripts, the application includes code highlighting; for programmers, this may be a big help.

The following screenshot shows 2 lines, that differ between my local and my website scripts. These lines are, as said, displayed with a yellow background, the text differences themselves being highlighted with pink background. (In this precise case, the difference in the first line has obvious reasons; the one in other line is a modification, that is not yet done in the server file).

WinMerge: Highlighting of different line content

And a screenshot showing an example of some lines of text, missing in one file (in this precise case, a part of code that I deleted in the local version and that hasn't yet be removed in the server version). A "gray empty" for the file, where text is missing, yellow (and beige) highlighting for the file, where supplementary text exists.

WinMerge: Highlighting of supplementary lines

Conserning deleted/supplementary lines, you must consider, that the program acts differently in the case, where you inserted supplementary lines and the one, where you moved some lines to another place. In the first case, the display is as described above, in the second one, the difference will appear twice, with the first time, lines missing in one file and the second time, lines missing in the other. This is not always wanted. If for example, you moved a memo paragraph without modifying its content to another place, the application will show 2 big parts with differences. This also was some problem with my database files, where the different records appear in the order they have been added to the table and that's often not the same locally and on the website (a work-around is to create the .csv files with a query containing an ORDER statement). This behaviour can't be changed by any settings. Simple reason: How should the program know that a paragraph at the end of one text file actually isn't something new, but just a paragraph with identical content, moved from another place in the document?

WinMerge has lots of other features and options. A detailed help text is included and accessible from the application window.



If you find this text helpful, please, support me and this website by signing my guestbook.