Remove trailing whitespace from each line.

Section: sed and Stream Editing

Trim trailing spaces

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

Useful before committing source files.

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 sed and Stream Editing
Reformat date
Convert YYYY-MM-DD into MM/DD/YYYY.
OpenIn sheetbashsame section
Prefix non-empty lines
Add a prefix only to non-empty lines.
OpenIn sheetbashsame section
Extract quoted content
Print only the content inside double quotes on each line.
OpenIn sheetbashsame section
sed regex replacement
Replace all runs of whitespace with a single space.
OpenIn sheetbash1 tag match
grep whole word
Find full-word matches in files.
Atomic group in PCRE
Avoid backtracking inside a grouped token.