๐Ÿ“š General & Other

Empty, Blank, and the Line That Is Not There

removes truly empty lines. also removes whitespace-only ones. The distinction accounts for most cases where blank-line removal appears not to work.

grep -v '^$' removes truly empty lines. grep -v '^[[:space:]]*$' also removes whitespace-only ones. The distinction accounts for most cases where blank-line removal appears not to work.

Carriage returns make lines non-empty

In a file with Windows line endings, an "empty" line contains \r. It does not match ^$ and survives the filter. This is the same invisible character that breaks suffix matching, and it produces the same bafflement.

The final newline is not a blank line

A well-formed text file ends with a newline after its last line. That trailing newline is a terminator, not an empty line โ€” but tools differ on whether they report a final empty field because of it, which is why a count is sometimes one higher than expected.

sed and awk alternatives

sed '/^$/d' and awk 'NF' both remove empties. awk 'NF' is the neatest: it keeps lines with at least one field, which by default means at least one non-whitespace character โ€” so it handles the whitespace-only case without a pattern at all.

Try it: Remove Blank Lines on SeoWolf's Notepad.