sed Commands

Complete sed commands reference — 38 commands across 2 categories. Quick reference cheat sheet for Linux, macOS & BSD.

Options (15)

ShortcutAction
sed -nsuppress automatic printing of pattern space
sed --debugannotate program execution
sed -e scriptadd the script to the commands to be executed
sed -f script-fileadd the contents of script-file to the commands to be executed
sed --follow-symlinksfollow symlinks when processing in place
sed -i[SUFFIX]edit files in place (makes backup if SUFFIX supplied)
sed -l Nspecify the desired line-wrap length for the 'l' command
sed --posixdisable all GNU extensions
sed -Euse extended regular expressions in the script (for portability use POSIX -E)
sed -sconsider files as separate rather than as a single, continuous long stream
sed --sandboxoperate in sandbox mode (disable e/r/w commands)
sed -uload minimal amounts of data from the input files and flush the output buffers more often
sed -zseparate lines by NUL characters
sed --helpdisplay this help and exit
sed --versionoutput version information and exit

sed Script Commands (23)

ShortcutAction
: labelLabel for b and t commands
#commentThe comment extends until the next newline (or the end of a -e script fragment)
textAppend text, which has each embedded newline preceded by a backslash
q [exit-code]Immediately quit the sed script without processing any more input, except that if auto-pri
Q [exit-code]Immediately quit the sed script without processing any more input
r filenameAppend text read from filename
R filenameAppend a line read from filename
b labelBranch to label; if label is omitted, branch to end of script
DIf pattern space contains no newline, start a normal new cycle as if the d command was iss
l widthList out the current line in a "visually unambiguous" form, breaking it at width character
PPrint up to the first embedded newline of the current pattern space
s/regexp/replacement/Attempt to match regexp against the pattern space
t labelIf a s/// has done a successful substitution since the last input line was read and since
T labelIf no s/// has done a successful substitution since the last input line was read and since
w filenameWrite the current pattern space to filename
W filenameWrite the first line of the current pattern space to filename
y/source/dest/Transliterate the characters in the pattern space which appear in source to the correspond
first~stepMatch every step'th line starting with line first
/regexp/Match lines matching the regular expression regexp
\cregexpcMatch lines matching the regular expression regexp
0,addr2Start out in "matched first address" state, until addr2 is found
addr1,+NWill match addr1 and the N lines following addr1
addr1,~NWill match addr1 and the lines following addr1 until the next line whose input line number
📄 View Printable Cheat Sheet — Download as PDF or print · 🧩 Combine with other tools

Related Shortcut Pages

awk Regex (Regular Expressions) Bash / Shell Vim tmux GNU Screen

Search 13,500+ shortcuts across 269 platforms

Explore All Platforms Practice Shortcuts
📜 Every shortcut on this page is taken from the official sed documentation — man7.org
🔧 Spotted an error or a missing shortcut? Suggest an edit on GitHub — every accepted fix goes live on this page, the API and the CLI.

🤖 Ask AI about sed shortcuts

Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"

ChatGPT Claude Perplexity Gemini Grok