Complete sed commands reference — 38 commands across 2 categories. Quick reference cheat sheet for Linux, macOS & BSD.
| Shortcut | Action |
|---|---|
| sed -n | suppress automatic printing of pattern space |
| sed --debug | annotate program execution |
| sed -e script | add the script to the commands to be executed |
| sed -f script-file | add the contents of script-file to the commands to be executed |
| sed --follow-symlinks | follow symlinks when processing in place |
| sed -i[SUFFIX] | edit files in place (makes backup if SUFFIX supplied) |
| sed -l N | specify the desired line-wrap length for the 'l' command |
| sed --posix | disable all GNU extensions |
| sed -E | use extended regular expressions in the script (for portability use POSIX -E) |
| sed -s | consider files as separate rather than as a single, continuous long stream |
| sed --sandbox | operate in sandbox mode (disable e/r/w commands) |
| sed -u | load minimal amounts of data from the input files and flush the output buffers more often |
| sed -z | separate lines by NUL characters |
| sed --help | display this help and exit |
| sed --version | output version information and exit |
| Shortcut | Action |
|---|---|
| : label | Label for b and t commands |
| #comment | The comment extends until the next newline (or the end of a -e script fragment) |
| text | Append 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 filename | Append text read from filename |
| R filename | Append a line read from filename |
| b label | Branch to label; if label is omitted, branch to end of script |
| D | If pattern space contains no newline, start a normal new cycle as if the d command was iss |
| l width | List out the current line in a "visually unambiguous" form, breaking it at width character |
| P | Print up to the first embedded newline of the current pattern space |
| s/regexp/replacement/ | Attempt to match regexp against the pattern space |
| t label | If a s/// has done a successful substitution since the last input line was read and since |
| T label | If no s/// has done a successful substitution since the last input line was read and since |
| w filename | Write the current pattern space to filename |
| W filename | Write 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~step | Match every step'th line starting with line first |
| /regexp/ | Match lines matching the regular expression regexp |
| \cregexpc | Match lines matching the regular expression regexp |
| 0,addr2 | Start out in "matched first address" state, until addr2 is found |
| addr1,+N | Will match addr1 and the N lines following addr1 |
| addr1,~N | Will match addr1 and the lines following addr1 until the next line whose input line number |
Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"