Compare and merge two files using WinMerge

Posted on November 17, 2008 at 5:54 am

If you have been on a situation wherein you need to compare two large text files or folders then this tutorial is for you.  In this example, given two almost identical text files,  I will show you how to determine the lines that have a mismatch.

In a manual brute force scenario, this is painstakingly difficult to do especially for large text files.  The free tool is called WinMerge and you can get it from http://winmerge.org/.  It is called WinMerge because it runs in Windows and it lets you merge the content of your files (i.e. you want to use the newer version of the text file).

You can begin comparing two files by going to the Open menu:

image

You will  be asked to enter the file names.  The file you entered on the left will appear on the left side of the screen while the right will appear on the opposite side.  The idea is to compare the two files side by side:

image

Press ok after entering the filenames.  In this case I entered two files called 1.epj and 2.epj which are plain text files.

Once you click OK, it will process the two files quickly and display the side-by-side comparison like below:

image

The leftmost side, called Location Pane, contains a scaled “map” of the text file where you can see 3 yellow lines where the relative position of the mismatches are.  This is very usable so you can navigate to the mismatches quickly.  You can click any part of the Location Pane to jump to that part of the file.

The main window will show the two files side-by-side and from this interface it is very easy to see where the mismatches are.

The View menu offers some functionality that you might find useful:

image

For people working with UNIX scripts, the white spaces are important.  You can use the View Whitespace option to be able to view the whitespace.  The white spaces will appear as a tick-like character:

image

If your boss or programs (i.e. UNIX scripts) are sensitive to white spaces, this is an excellent tool to determine where those “invisible” spaces are.

Upon determining the differences, there are times that we need to merge the files.  In this case I can replace the line from the left with the line from the right using the replace buttons:

image

You can use the button to replace a line on the left side by the line on the right side (or vice versa).

image

After clicking the button, the mismatch will disappear (after it “merged” the line):

image

Overall, WinMerge is one powerful dif tool. It is easy to use and should be good enough for most file and folder comparison.  It’s merging capability also helps most writers who need to use a new version of a certain portion of a document.

Ben Carigtan writes about technology, computers, websites and how to get the best out of them.

» Filed Under Computer Tips

Related Posts

Comments

2 Responses to “Compare and merge two files using WinMerge”

  1. restful web said on :

    WinMerge is a must-have tool for me, especially when working with shared version control systems like subversion or CVS. Saves me a lot of time.

    One of its best features is the ability to compare two directories. That’s great when you have a bug-fix branch that needs to be merged with the development branch.


    Pingbacks
  1. Find the differences between files using P4Merge Says:

    [...] 17Sep Previously, I wrote about a free program called WinMerge that lets you quickly compare two files to see the differences. It’s a powerful difference tool and one that I highly [...]

Please post your comments/suggestions!