What this template solves
Use this template to normalize inconsistent spacing in copied text, reports, tables, or generated config fragments before further processing.
Sample input
alpha beta gamma
one twoPrompt to start from
Normalize repeated spaces and tabs into a single space
Expected command
sed 's/[[:space:]]\+/ /g'Tags
Best for
- Clean copied terminal output before storing it in docs.
- Normalize spacing in generated reports or exports.
- Make uneven text easier to diff, parse, or share.
How to use this template
- 1Check whether repeated spaces and tabs should collapse into a single space.
- 2Copy the sed command that normalizes consecutive whitespace.
- 3Preview on representative sample text first, then apply the platform-specific file-edit variant if needed.
Template FAQ
How do I normalize repeated spaces and tabs with sed?
A common pattern is `sed 's/[[:space:]]\+/ /g'`, which collapses repeated whitespace into a single space. This is useful when copied text, exports, or reports contain uneven spacing.
When should I use normalize-whitespace instead of removing trailing spaces only?
Use normalize-whitespace when inconsistent spacing appears throughout the line, not just at the end. It is better for cleaning pasted text, tabular exports, and other content with uneven internal spacing.
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:]]\+$//'Delete empty lines
CleanupRemove blank and whitespace-only lines.
sed '/^\s*$/d'Collapse multiple spaces
CleanupCollapse repeated spaces into a single space while keeping line structure.
sed 's/ */ /g'