Angus Comber
Angus Comber

Reputation: 9708

Text processing to concatenate lines (ie remove end of line char)

I have a list of lines like this:

a+
b+
c+
d+
e+
f+
... you get the idea...

I want to end up with a+b+c+d+e etc

I was trying with emacs but couldn't work out how to do such a thing. anyone any ideas?

One thing that does work is c-m-% [paste in selected after + on one line to beginning of next row] [nothing]

There must be something to insert for carriage return?

Upvotes: 0

Views: 124

Answers (4)

Stefan
Stefan

Reputation: 28541

Have you tried just `M-q' ? The spacing is different, and it will use several lines if you have many of those thingies, but otherwise, it seems like a funny alternative.

Upvotes: 1

fycth
fycth

Reputation: 3489

M-x
replace-regexp
RET
C-q C-j
RET
RET

Upvotes: 0

How about simply replacing EOLs by nothing?

M-%C-q C-jRETRET

Explanation:

  • M-% : query-replace
  • C-q : quote the following character
  • C-j : end-of-line character
  • first RET : validate the search string
  • second RET : validate the (empty) replacement string

Upvotes: 3

Magnar
Magnar

Reputation: 28830

Do you have a buffer with those lines in it? In that case, you could create a simple macro:

F3  ;; record macro
C-e ;; end of line
C-d ;; delete newline
F4  ;; save macro

Then either press F4 repeatedly until you're done, or do C-0 F4 to do it all in one swoop.

Upvotes: 2

Related Questions