Linux – Transpose every n lines to one row

Transpose every n lines to one row… here is a solution to the problem.

Transpose every n lines to one row

I want to merge a bunch of n rows into one line and don’t know how to do it. Any help appreciated.

A bunch of 11 words, then a

blank line, then a bunch of ll words, then blanks, like… Wait a minute.

Example:

cat filename

hi
hello
how
are
you
i
am
fine
how
are
you

hi
how
is
she
doing
i 
have
not 
herd 
from
her

..
..

Expected output:

cat newFile

hi hello how are you i am fine how are you 
hi how is she doing i have not heard from her 
..
..

Solution

Via awk.

$ awk -v RS= '{gsub(/\n/, " ")}1' file
hi hello how are you i am fine how are you
hi how is she doing i  have not  herd  from her

Related Problems and Solutions