Skip to main content
added 5 characters in body
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

With awk:

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

The ORS variable specifies the output record separator. If the line number of fields is zero (the line is empty) 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.

With awk:

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

The ORS variable specifies the output record separator. If the line number is zero (the line is empty) 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.

With awk:

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

The ORS variable specifies the output record separator. If the number of fields is zero (the line is empty) 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.

added 8 characters in body
Source Link
chaos
  • 49.3k
  • 11
  • 127
  • 147

With awk:

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

The ORS variable specifies the output record separator. If the line if emptynumber is zero ($0the line is not setempty) 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.

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.

With awk:

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

The ORS variable specifies the output record separator. If the line number is zero (the line is empty) 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.

Posixified
Source Link
cuonglm
  • 158.2k
  • 41
  • 342
  • 420

With awk:

awk '{ORS=" ";}; !$0{ORS="\n"}1';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.

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.

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.

Source Link
chaos
  • 49.3k
  • 11
  • 127
  • 147
Loading