How to use awk or sed to convert rows to columns

awksedtext processing

I need to transpose a file.

Input file:

1/1/1111
1
2
3
4

2/2/2222
5
6
7
8

Output:

1/1/1111 1 2 3 4
2/2/2222 5 6 7 8

Best Answer

With sed:

$ sed -e '
  :1
  $!N
  /\n$/{
    P
    d
  }
  s/\n/ /
  t1
' <file
Related Question