Skip to main content
2 of 4
Posixified
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

With awk:

awk '{ORS=" ";}; !$0{ORS="\n"};1' file

The ORS variable specifies the output record separator. If the line if empty ($0 is not set) then the record separator should be a newline, else a space. The 1 at the end just means a positive condition, so awk prints the whole line.

chaos
  • 49.3k
  • 11
  • 127
  • 147