Why this topic matters
Templates for removing empty lines, trimming trailing spaces, and rewriting line starts to keep files clean and consistent.
This topic page groups together whitespace cleanup searches such as deleting empty lines, normalizing whitespace, collapsing multiple spaces, and preserving cleaner paragraph spacing.
Templates in this topic
Templates for removing empty lines, trimming trailing spaces, and rewriting line starts to keep files clean and consistent.
Delete empty lines
CleanupRemove blank and whitespace-only lines.
sed '/^\s*$/d'Remove duplicate blank lines
CleanupCollapse repeated blank lines so only one empty row remains.
sed '/^$/N;/^\n$/D'Collapse multiple spaces
CleanupCollapse repeated spaces into a single space while keeping line structure.
sed 's/ */ /g'Normalize whitespace
CleanupCollapse repeated spaces and tabs into one clean separator.
sed 's/[[:space:]]\+/ /g'Remove trailing spaces
CleanupDelete trailing spaces and tabs at the end of each line.
sed 's/[[:space:]]\+$//'Remove leading comment markers
RewriteRemove the leading # and following spaces from each line.
sed 's/^#\s*//'