Compare files in Linux

Categories: Utilities Web services

Not long ago I was working with some .po files and needed a nice and simple diff program to merge 2 files. First I tried the multi-purposed text editor vim.

Using vim as a diff and merge tool:

with Andrej’s article I found some nice tips & tricks and the Vim manual for diff tasks. Some useful commands,

  • vim -o one.txt two.txt three.txt” (for horizontal split), “vim -O one.txt two.txt three.txt ” (for vertical split)
  • go to the next diff point   ” ]c “; go to previous diff point “ [c
  • merge to original “do“, merge from original “dp“.

The window you’ll be looking at will look something like this:

Another tool I found was Meld. This program was incredibly simple to use and visually simple to work with.

Using Meld Diff Viewer:

  • open the files (or directories) which you’d like to compare;
  • you will visually see where on the original file the text is at on the other file(s) being compared. Specially useful if the text in the files you’re comparing are in completely separate lines;
  • clicking on arrows between the files being compared, the text will go to or from the original file.

if you’re working on the command line, vim will do the job quite nicely but can be troublesome to inform you if text in both files are the same but spaced out in different line numbers. On the other hand, Meld was the tool I used for the task since there was basically no learning curve to get started and it displayed very well differences and matches in the file even if text were separated by dozens of line between both files I was comparing.

See also