Replace all runs of whitespace with a single space.

Section: grep, egrep, and ripgrep

sed regex replacement

bash
bash
sed -E 's/[[:space:]]+/ /g' file.txt
Explanation

Great for one-line normalization tasks.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing grep, egrep, and ripgrep
grep whole word
Find full-word matches in files.
OpenIn sheetbashsame section
ripgrep ignore case
Search recursively with ripgrep case-insensitively.
OpenIn sheetbashsame section
ripgrep with PCRE2
Use lookbehind or advanced features through PCRE2 mode.
OpenIn sheetbashsame section
Invert match
Show lines that do not match a pattern.
OpenIn sheetbashsame section
Alternation in egrep style
Search for one of several tokens.
OpenIn sheetbashsame section
awk regex condition
Print lines matching a regex in awk.
OpenIn sheetbashsame section