Bash 5 reference · Text and System Tools

sed (Linux command)

Edit text streams: substitute with s/old/new/, delete or print lines by number or pattern, and edit files in place.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

sed [OPTIONS] 'SCRIPT' [FILE...]

Parameters

ParameterDescription
s/a/b/g Replace all matches on each line.
-n 'Np' Print only line N.
/pat/d Delete matching lines.
-i[SUFFIX] Edit files in place, optionally keeping a backup.
-E Extended regex with capture groups.

Examples

Substitute and delete
echo 'Hello hello' | sed 's/hello/Hi/gI'
printf '# c\nkey=1\n' | sed '/^#/d'

Output

Hi Hi
key=1

Run this on your computer — see “Get Started” for setup.

In place with a backup
echo 'debug=true' > app.conf
sed -i.bak 's/true/false/' app.conf
cat app.conf app.conf.bak

Output

debug=false
debug=true

Run this on your computer — see “Get Started” for setup.

Was this page helpful?