How to compare and merge text files on Linux (part 2)
This post is a response to the overwhelming comments about Meld (and other tools) on my previous article on text files comparison and merging tools. While my intention wasn’t to focus on code text only but to also present something useful to word editors and writers as well, but the coders community objected for the “shallowness” of the previous post so here we go with part 2.eval(ez_write_tag([[728,90],’howtoforge_com-box-3′,’ezslot_5′,106,’0′,’0′]));
Start Meld and hit the “File Comparison” button located on the center. Next, press the two buttons that just appeared under the initiating options and choose the files you want to compare.eval(ez_write_tag([[580,400],’howtoforge_com-medrectangle-3′,’ezslot_2′,121,’0′,’0′]));
After the files are loaded, Meld indicates clearly all of the differences between the two files on its neat interface. The arrow buttons on the top panel can be used to navigate to the next/previous difference. In the “Changes” menu located in the top panel, you will find merging options. Only valid entries are available though.
Meld also supports syntax highlighting for the easier review of the text. Select the “Edit” menu on the top and choose the “Preferences”. From there, choose the first tab (Editor) and tick the “Use Syntax Highlighting” entry to enable the feature.
You can even add a third file for comparison by ticking the “3-way comparison” option in the initial screen. Folder comparisons are also possible on Meld.
Another (apparently) popular choice for text comparison is the “vimdiff” command. Open a terminal in the location of the two text files and type the vimdiff command followed by the two filenames: “vimdiff filename_one.h filename_two.h”eval(ez_write_tag([[580,400],’howtoforge_com-medrectangle-4′,’ezslot_1′,108,’0′,’0′]));
This will display the two files with highlighting on the changes. Syntax highlighting is also available so you can easily browse and read the files. You can also add more than two text files on the command if you have enough space for it.
If you don’t like the terminal, you can always open Gvim and choose the “File/Split Diff” option to load the text files.
There are some vimdiff commands that you can use to merge the text of the compared files. To merge changes from the right to the left, you can use the “do” parameter, while the opposite is done with the “dp” command. Before proceeding to merge though, you may want to jump to the changes (next/previous) for a last review. This is done with “[c” and ”]c” which correspond to “previous” and “next” change.
If the above are still not what you were looking for, you may also take a look at Beyond Compare, Xxxdiff, Kompare, and KDiff3. They have their pros and cons, but generally all of them work well. If I had to choose one tool from both posts, I would choose Meld for its straight forward graphical interface and “coolest looking” and most accurate highlighting.