21

For e. g., less has option --squeeze-blank-lines (or -s in short) and it squeezes multiple blank lines into single blank line, buuut, less wouldn't do this being used as filter (i. e., having its output sent not to a tty).

Similar option can be found in cat too, it's also called -s usually, and it also makes single blank line instead of several.

What about removing empty/blank lines all together? One approach I can think of is using grep, but may be I've overlooked something more simple?

poige
  • 6,195
  • 2
  • 30
  • 57

1 Answers1

39

Use awk!

echo -e "dada

ada

bada

" | awk NF

results in

dada
ada
bada
MatthewRock
  • 6,826
  • 6
  • 31
  • 54
  • 7
    This post explains how `awk NF` works: https://stackoverflow.com/questions/23544804/how-awk-nf-filename-is-working – wisbucky Apr 25 '19 at 22:07