sed

Stream editor for filtering and transforming text. Great for in-place edits, line-based replacements, and quick data cleanup.

Synopsis

sed [options] 'script' file(s)

Core Options

-n

Suppress automatic printing; use 'p' to print explicitly.

-E

Use extended regular expressions.

-i

Edit files in place (use -i.bak to keep a backup).

-e 'script'

Add multiple editing commands.

-f file

Read sed commands from a file.

Usage Examples

Simple Replace

Replace all occurrences of 'foo' with 'bar'.

sed 's/foo/bar/g' input.txt

Print a Line Range

Print lines 10 to 20 only.

sed -n '10,20p' input.txt

Delete Blank Lines

Remove empty lines from a file.

sed '/^$/d' input.txt

In-place Edit with Backup

Replace tabs with spaces and keep a .bak file.

sed -i.bak 's/\t/  /g' config.txt

Multiple Commands

Delete comments and trim trailing spaces.

sed -e 's/#.*$//' -e 's/[[:space:]]*$//' file.conf
Built for builders.