sed 's/<old>/<new>/' <file>Replaces the first match on each line and prints the result; the file is unchanged.
Example
sed 's/http/https/' urls.txtA stream editor for filtering and transforming text: substitutions, deletions and in-place file edits.
sudo apt install sedsed 's/<old>/<new>/' <file>Replaces the first match on each line and prints the result; the file is unchanged.
Example
sed 's/http/https/' urls.txtsed 's/<old>/<new>/g' <file>Replaces every match on each line.
Example
sed 's/foo/bar/g' config.txtsed 's/<old>/<new>/gI' <file>Case-insensitive replacement (GNU).
Example
sed 's/error/ERROR/gI' app.logsed 's#<old>#<new>#g' <file>Use a different delimiter when the pattern contains slashes.
Example
sed 's#/var/www#/srv/www#g' site.confsed -E 's/(<regex>)/[\1]/g' <file>Extended regex with capture groups; \1 refers to the first group.
Example
sed -E 's/([0-9]+)/[\1]/g' data.txtsed -i 's/<old>/<new>/g' <file>Edits the file in place. On macOS/BSD use sed -i '' instead.
Example
sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_configsed -i.bak 's/<old>/<new>/g' <file>Edits in place and keeps a backup with the given suffix.
Example
sed -i.bak 's/8080/9090/' app.confsed -n '<n>p' <file>Prints only line n.
Example
sed -n '42p' app.logsed -n '<a>,<b>p' <file>Prints a range of lines.
Example
sed -n '100,120p' app.logsed -n '/<start>/,/<end>/p' <file>Prints everything between two patterns, inclusive.
Example
sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' bundle.pemsed '/<pattern>/d' <file>Deletes matching lines — here, comments.
Example
sed '/^#/d' nginx.confsed '/^$/d' <file>Deletes empty lines.
Example
sed '/^$/d' notes.txtsed '<n>d' <file>Deletes line n, such as a CSV header.
Example
sed '1d' data.csvsed '<n>i <text>' <file>Inserts a line before line n.
Example
sed '1i #!/bin/bash' script.shsed '/<pattern>/a <text>' <file>Appends a line after each match.
Example
sed '/\[mysqld\]/a bind-address = 127.0.0.1' my.cnfsed 's/^[ \t]*//;s/[ \t]*$//' <file>Trims leading and trailing whitespace; several commands are separated by semicolons.
Example
sed 's/^[ \t]*//;s/[ \t]*$//' list.txt