Raw Input Desired Output
Line  1
Line  2
Line  3
Line  4
Line  5
Line  6
Line  7
Line  8
Line  9
Line 10
Line 11
Line 12
Line 13
Line  1 Line  2 Line  3 Line  4
Line  5 Line  6 Line  7 Line  8
Line  9 Line 10 Line 11 Line 12
Line 13
Script and Comments
Script1
[ 1] :loop
[ 2] $!{
[ 3] N
[ 4] /(\n[^\n]*){3}/!b loop
[ 5] }
[ 6] s/\n/ /g
Comments -r
  1. To convert every N lines to one,
    • First we have to have these N lines in PS:
      when PS has the first one of these N lines, N-1 `N' commands will append the following N-1 lines to PS.
    • Then replace the embedded newline characters with spaces.
    • Although the RE matching PS with N lines is ^([^\n]*\n){N-1}[^\n]*$ or ^[^\n]*(\n[^\n]*){N-1}$, since there will be no more than N lines in PS, (\n[^\n]*){N-1} suffice. Taking performance into account, using (\n.*){N-1} is not encouraged.
  2. Steps [1] thru [5] constitute a loop which iterates until PS have 4 lines.