unix sed remove blank lines

I am using sunos. Does unix sed not have the ability to remove blank lines in the middle of a file? I tried all the sed solutions listed here.

These four looked most promising. They only deleted blank lines at the end of a file. Not in the middle of a file.

The awk solution works. Would just prefer sed since I am using sed already.

awk 'NF' file

'/^$/d' deletes really empty lines, everywhere in the file.
'/^ *$/d' deletes empty lines or lines with only spaces.

A space or tab is \s but is recognized in GNU sed only.
[[:space:]] is any space-like character in POSIX, in Solaris /usr/xpg4/bin/sed

1 Like