Merge two Emacs buffers?

Given two separate emacs buffers, how can I combine them by appending the first lines of each, then the second, etc.? I probably need to add a space after each line in buffer # 1, so I won’t give, for example, β€œa b1 2”.

Buffer # 1

 ab
 ac
 cx

Buffer # 2

 12
 5 4
 3 2

Result

 ab 1 2
 ac 5 4
 cx 3 2
+8
emacs elisp
source share
4 answers

You can use rectangles for this. Just copy the contents of buffer 2, and then the rectangular Yankees (Cx ry) to buffer 1, and the right field β€œb” in the first line.

+15
source share

Use Mx 2C-associate and Mx 2C-merge . You can use Ch v 2C-windows-width or Mx 2C-shrink-window-horizontal.

+5
source share

I usually use the paste tool for such applications (although Emacs, though ..). If you are using Linux, it should be available by default.

It's simple:

 $ paste file1 file2 > file3 

which will merge the two files 'file1' and 'file2' into the output file 'file3' as you requested. By default, TABs are used as column separators, but this can be changed using the -d option.

+4
source share

If you don't mind doing merging outside of emacs, you can save these two files and merge them with awk.

Have a look at this example: http://www.linuxquestions.org/questions/linux-newbie-8/awk-question-331224/#post1682282

0
source share

All Articles