What this template solves
Use this template to clean text files, notes, exports, or config snippets by removing empty lines and whitespace-only rows in one pass.
Sample input
line one
line two
line threePrompt to start from
Delete empty lines in the text
Expected command
sed '/^\s*$/d'Tags
Best for
- Clean copied notes before committing them to a repo.
- Normalize whitespace in exported lists or generated text files.
- Remove visual gaps from config or log fragments before further parsing.
How to use this template
- 1Check whether the file contains truly blank lines, whitespace-only lines, or both.
- 2Copy the sed pattern that deletes empty rows.
- 3Run it on a sample or backup first, then apply the file-edit variant for your platform.
Template FAQ
How do I delete empty lines and whitespace-only lines with sed?
A common command is `sed '/^\s*$/d'`, which removes blank rows as well as lines made only of spaces or tabs. This template packages that exact workflow into a reusable landing page with sample input and file-edit guidance.
Will deleting empty lines change non-empty content?
No. This pattern targets only lines that contain no visible characters. It is useful for cleaning exports, notes, logs, and config fragments without touching the real text on populated lines.
Related templates
Explore nearby sed workflows that target similar replace, cleanup, filtering, or rewrite tasks.
Remove trailing spaces
CleanupDelete trailing spaces and tabs at the end of each line.
sed 's/[[:space:]]\+$//'Normalize whitespace
CleanupCollapse repeated spaces and tabs into one clean separator.
sed 's/[[:space:]]\+/ /g'Remove duplicate blank lines
CleanupCollapse repeated blank lines so only one empty row remains.
sed '/^$/N;/^\n$/D'