Substitute every match on each line.
Section: sed Substitution
Replace all occurrences per line
bash
bash
sed 's/foo/bar/g' file.txtExplanation
The `g` flag applies the replacement globally across the line.
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 Substitution