sed

Stream editor for filtering and transforming text.

What it does

sed processes text line-by-line, applying editing commands such as substitution, deletion, and insertion. It is widely used for quick text transformations in pipelines and scripts.

Quick Start

# Replace text
sed 's/foo/bar/' file.txt

# Replace globally
sed 's/foo/bar/g' file.txt

Examples

# Delete lines containing a pattern
sed '/error/d' logfile

# Print only matching lines
sed -n '/error/p' logfile

# In-place edit (GNU sed)
sed -i 's/old/new/g' file.txt

# Replace first occurrence per line
sed 's/foo/bar/' file.txt

Notes