Online Linux Terminal Logo
OnlineLinuxTerminal
Text ProcessingCLI Reference

$sed

Stream editor for filtering and transforming text using pattern substitutions.

Syntax DefinitionPOSIX standard
sed [OPTIONS] SCRIPT [INPUT-FILE...]
Linux Community2.4k Online

Chat with real Linux users, learn new commands & get free cheat sheet PDFs.

Try `sed` Live in Interactive Sandbox

Zero-install client simulation with real-time feedback.

Open in Fullscreen Workspace↗
bash — terminal

Overview & How sed Works

`sed` (Stream Editor) performs basic text transformations on an input stream or file. Its most famous capability is search-and-replace using the `s/find/replace/g` syntax, allowing automated batch editing of source code and configurations without opening a visual editor.

Common Flags & Command Options

Flag / OptionDescription
-iEdit files in place directly instead of printing to stdout.
-e [script]Add the script to the commands to be executed.
-nSuppress automatic printing of pattern space.

Practical Real-World Examples

Example #1Substitute string patterns in text output
echo "localhost:3000" | sed "s/3000/8080/g"

Replaces port 3000 with 8080 in the stream.

Sample Output:
localhost:8080

Frequently Asked Questions

What does the /g at the end of a sed substitution mean?

`/g` stands for global. It replaces all occurrences of the matching pattern on each line, rather than just the first occurrence.