sed

Stream editor — transform text using substitution, deletion, and insertion.

medium risk

interactive breakdown — edit the command and press Explain
$ 
⚠ Risks & cautions
What it does

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.

Common flags
FlagMeaning
-i --in-placeEdit file in-place (use -i.bak to keep a backup)
-n --quietSuppress automatic printing of pattern space
-e --expressionAdd a script command to execute
-r --regexp-extendedUse extended regular expressions
Examples
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 →
Pro tip

Always use `-i.bak` instead of bare `-i` — it creates a backup and is portable across Linux and macOS.

Related
awk grep tr vim
Open the full explainer →More in Text Processing

Reference text is hand-written and may be incomplete — check man sed for your version. Test destructive commands on a non-production system first.