How to merge two files using text mode in Linux
In Category Linux Tools Unix VI
The Linux provides a command “vimdiff” which can open two files using standard “vim” editor but in two separate logical windows. This is a text-mode based tool. This tool highlights the differences between two files so that the user can inspect the differences and change or move the contents from one window to the other.
First of all, the two file which need merging have to be opened with “vimdiff” as shown below.
vimdiff file1.c file2.c
User can type “Ctrl w w” key combination to switch between windows i.e effectively between two files. You can use standard “vim” commands to copy and paste or delete some text of both files. If user needs to move certain portion of text from one file to other, he/she needs to first copy the text in the source file, switch to the other window using “Ctrl w w” key combination and then use the standard “p” command to paste the contents.
User can modify and save one of or both the files. To save file, user can move to appropriate window and type the standard “:w” command to save it.
Using the “vimdiff” command you can even open and merge up to four files at one.
You can even merge a local and a file residing in an remote host using ssh as shown below.
[nick@techpulp ~]# vimdiff scp://nick@neo.techpulp.com//share/source/bingo.c ./bingo.c
Recent Comments