Cleanup

Normalize whitespace

Collapse repeated spaces and tabs into one clean separator.

What this template solves

Use this template to normalize inconsistent spacing in copied text, reports, tables, or generated config fragments before further processing.

Open the workspace with this template preloaded, then refine it for your own file and text pattern.

Sample input

alpha    beta		gamma
one	 two

Prompt to start from

Normalize repeated spaces and tabs into a single space

Expected command

sed 's/[[:space:]]\+/ /g'

Tags

cleanupwhitespaceformattingtext

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

  1. 1Check whether repeated spaces and tabs should collapse into a single space.
  2. 2Copy the sed command that normalizes consecutive whitespace.
  3. 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.

Normalize whitespace Sed Template | AskSed