Add a prefix only to non-empty lines.
Section: sed and Stream Editing
Prefix non-empty lines
bash
bash
sed -E '/^$/! s/^/# /' notes.txtExplanation
Combines a regex address with substitution.
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