Skip to main content

Command referencesed

sed command (Linux / bash / sh / zsh)

Linuxbashshzshtextintermediate

What it does

Transform text streams with scripted substitutions and edits. When people search for the sed command linux examples, they usually want sed's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Transform text streams with scripted substitutions and edits.

Syntax

sed [OPTION]... SCRIPT [FILE]...

Common options

Flag / optionMeaning
-nSuppress automatic printing.
-EEnable extended regular expressions.
-i[SUFFIX]Edit files in place, optionally keeping a backup.
-e SCRIPTAdd a script to execute.

Practical examples

Replace text

sed 's/http:/https:/g' links.txt

Writes transformed lines to standard output.

Print a range

sed -n '10,20p' app.log

Prints only lines 10 through 20.

Edit with backup

sed -i.bak 's/debug=true/debug=false/' app.conf

Updates the file and retains a .bak copy.

Common mistakes

  • Using `-i` without a backup before testing the expression.
  • Forgetting that sed regular-expression syntax and `-i` behavior vary across platforms.

FAQ

What does sed do in Linux?

Transform text streams with scripted substitutions and edits.

How do I use sed from the terminal?

Start with `sed [OPTION]... SCRIPT [FILE]...`, then choose only the options needed for the task.

What is a practical sed example?

Try `sed 's/http:/https:/g' links.txt` — Writes transformed lines to standard output.

Can I use sed in a shell script?

Yes. sed works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.