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
Syntax
sed [OPTIONS] 'SCRIPT' [FILE...]
Parameters
| Parameter | Description |
|---|---|
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
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.
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.
Related
grep· Search files or input for lines matching a pattern, with options for case, counts, context, recursion and regex.awk· Process text by fields: print and filter columns, compute sums and group totals, with a small built-in language.tr· Translate, squeeze or delete characters, such as changing case, removing carriage returns or splitting words onto lines.- Bash sed: Edit Text Streams · tutorial