Cleanup

Collapse multiple spaces

Collapse repeated spaces into a single space while keeping line structure.

What this template solves

This template is useful when text contains irregular spacing and you want to compress repeated spaces without changing line breaks.

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

Collapse multiple spaces into a single space

Expected command

sed 's/  */ /g'

Tags

cleanupspacesformattingtext

Best for

  • Normalize copied text with uneven spacing.
  • Clean reports or tabular exports before sharing.
  • Make noisy plain text easier to diff or parse.

How to use this template

  1. 1Check whether only repeated spaces should collapse, not tabs or line breaks.
  2. 2Copy the sed command that compresses multiple spaces.
  3. 3Preview on representative text before applying the file-edit command.

Template FAQ

How do I collapse multiple spaces into one with sed?

A common pattern is `sed 's/ */ /g'`, which compresses repeated spaces into a single space while leaving line breaks intact. It is helpful for copied text and uneven plain text formatting.

What is the difference between collapse-multiple-spaces and normalize-whitespace?

Collapse-multiple-spaces focuses only on repeated spaces, while normalize-whitespace is broader and can also target tabs or other whitespace classes depending on the command pattern.

Related templates

Explore nearby sed workflows that target similar replace, cleanup, filtering, or rewrite tasks.

Collapse multiple spaces Sed Template | AskSed