Cheatsheet: sed
Last updated 2026-06-21
Substitution
Replace the first match on each line
Replace every match on each line
Replace case-insensitively with GNU sed
Use a different delimiter to avoid escaping slashes
Edit a file in place with a backup
Printing and deleting
Print only matching lines
Print a specific line
Print a range of lines
Delete matching lines
Delete blank lines
Delete a range of lines
Ranges and expressions
Substitute only within a line range
Substitute only between two matching markers
Run multiple sed expressions
Use extended regular expressions
Reuse capture groups in a replacement
Insert and append
Insert a line before a match
Append a line after a match
Change an entire matching line
Read from standard input in a pipeline
See also: