awksedvim

Remove only odd lines' line breaks, with Vim, sed or awk


I have the following file:

line 1
abc
line 2
def
line 3
ghi
.....
.....

I need it to become:

line 1 abc
line 2 def
line 3 ghi
......
......

I know how to remove newlines, but not odd or even line breaks.


Solution

  • This might work for you (GNU sed):

    sed -i 'N;s/\n/ /' file
    

    Append the following line and replace the newline with a space.

    Alternative using paste:

    paste -sd' \n' file