Stream editor — transform text using substitution, deletion, and insertion.
medium risk
sed reads input line by line applying editing commands. The `s/pattern/replacement/flags` command substitutes text. -i edits files in place. Always test with a dry run (without -i) before modifying files.
| Flag | Meaning |
|---|---|
-i --in-place | Edit file in-place (use -i.bak to keep a backup) |
-n --quiet | Suppress automatic printing of pattern space |
-e --expression | Add a script command to execute |
-r --regexp-extended | Use extended regular expressions |
sed -i.bak 's/localhost/db.prod.internal/g' app.confReplace hostname in config, keeping .bak backup · explain & risk-check →sed -n '100,200p' huge.logPrint only lines 100 to 200 from a large log · explain & risk-check →sed '/^$/d' config.txtRemove all blank lines from a file · explain & risk-check →Always use `-i.bak` instead of bare `-i` — it creates a backup and is portable across Linux and macOS.
Reference text is hand-written and may be incomplete — check man sed for your version. Test destructive commands on a non-production system first.