• Compare files in Linux

    by  • July 26, 2009 • Utilities, Web services • 4 Comments

    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:

    vimdiff

    Where text highlighted red will display text which doesn’t match from the files being compared.

    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.

    meld_file1

    Conclusion:

    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.

     

    If you enjoyed this post, make sure you subscribe to my RSS feed!

    About

    Using computers since the early 90s. Old timer with windows, more recently converted to Linux.

    http://opencomputer.net

    4 Responses to Compare files in Linux

    1. July 28, 2009 at 7:10 am

      Kdiff and NetBeans are very good too…thanks.

    2. April 29, 2011 at 10:46 am

      The file comparisson in Linux is very easy to perform in this way. I believe is a good opportunity to have the access at the files in Linux.

    3. May 28, 2011 at 9:33 pm

      Netbean+Ubuntu is great !

    4. March 10, 2012 at 8:24 pm

      It is really interesting and I am sure that other people thinks this too.

    Leave a Reply

    Your email address will not be published. Required fields are marked *