Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

How to compare and merge text files on Linux


Comparing text files requires time, effort, a large monitor and a good amount of patience, or simply just the right tools to do it without any of the aforementioned. If you are an editor that has to deal with multiple versions of a text file, or a developer that wants to check the various code revisions of a file, then the following tutorial is for you.

Diffuse

Diffuse is a handy little text comparer and merger that was built with the developer in mind. It features an easy to use graphical interface that positions the two text files side by side. The key element of this software tool is its highlighting abilities that automatically detect the differences between the two files and highlight them. Moreover, Diffuse can detect the format of the file and utilize another set of highlighting methods. For example, in the following picture, you can see two different versions of an XML file. Diffuse is showing the different “parts” with orange, as well as the exact points of difference with red.

pic_1

You may change the format through the “Format” options menu located on the top panel. The “Merge” options menu allows for a set of merging or copying options from left to right or the other way around. For easier and quicker browsing of the differences, especially in longer files you may use the ctrl+up arrow or ctrl+down arrow hotkeys that correspond to “view previous difference” and “view next difference” respectively.

There are many text codecs supported (all that I know of), and you can even set up a local repository directory through the “Edit/Preferences/Version Control” settings menu to allow Diffuse to import files from your Git, CVS, Bazaar or Mercurial folder. You can of course import simple text files as well by pressing the “open a file” button located on the top left of each document area.

pic_2

While this is perfectly doable with Diffuse, I would suggest that editors use the LibreOffice compare features when they deal with written content files.

LibreOffice

The first thing you need to do is to open the first version of the file with LibreOffice. Then you go to the top panel and choose the “Edit/Compare Document” option. This will open up a file manager dialog that will allow you to choose the updated version of the file and upon its selection you will be given the differences and a control dialog.

pic_3

You may choose every change entry from the control window and the corresponding line will be highlighted on the document.

pic_4

For even better control, you can use the “Filter” tab. This allows you to show edits from a particular editor, choose specific actions (insertion, deletion, format changes, table changes), or even specify a certain time period and only show changes that happened during this period. This is especially helpful for chief editors who want to check the results of collaborative editing work.

Update:

Here is part 2 of this article that covers Meld and Vim.

https://www.Kreationnext.com/tutorial/compare-merge-text-file-linux-part-2/

Comments

comments