sed

The stream editor, which applies editing commands such as find-and-replace to each line of text passing through it.

In more detail

s/old/new/ replaces the first match on each line and s/old/new/g every match. -n with p prints only the lines you select. The patterns are regular expressions, and the whole program should be in single quotes so the shell leaves it alone.

Examples

sed 's/error/ERROR/g' app.log
sed -n '2,4p' poem.txt
python3 dora_metrics.py fixture | sed -n '4p'
sed s/second/SECOND/ c.txt
sed "s|^hosts/||" strips a prefix from every line.

Related terms

Taught in

References