[sed] Delete blank lines

Created on November 30, 2026

Use /^[[:space:]]*$/d to remove empty lines and lines containing only whitespace such as spaces or tabs.

sed '/^[[:space:]]*$/d' dummy.txt

Example dummy.txt

apple


orange
banana

Output

apple
orange
banana

The expression matches from the start of the line to the end of the line. The d command discards each matching line.

Bash Shell command sed