command addr command addr-start,addr-end command addr! command addr-start,addr-end! command
-n , --quiet , --silent | suppress automatic printing of pattern space |
--debug | annotate program execution |
-e script , --expression=script | add the script to the commands to be executed |
-f script-file , --file=script-file | add the contents of script-file to the commands to be executed |
--follow-symlinks | follow symlinks when processing in place |
-i[SUFFIX] , --in-place[=SUFFIX] | edit files in place: change a file instead of writing to STDOUT. (makes backup if SUFFIX supplied) |
-b , --binary | open files in binary mode (CR+LFs are not processed specially) |
-l N , --line-length=N | specify the desired line-wrap length for the `l' command |
--posix | disable all GNU extensions. |
-E , -r , --regexp-extended | use extended regular expressions in the script (for portability use POSIX -E ). |
-s , --separate | consider files as separate rather than as a single, continuous long stream. |
--sandbox | operate in sandbox mode (disable -e , -r and -w commands). |
-u , --unbuffered | load minimal amounts of data from the input files and flush the output buffers more often |
-z , --null-data | separate lines by NUL characters |
--help | display this help and exit |
--version | output version information and exit |
-e
, --expression
, -f
or --file
option is given, then the first non-option argument is taken as the sed script to interpret. All remaining arguments are names of input files; if no input files are specified, then the STDIN is read. # comment | # introduces a comment. No address is allowed with this «command» |
= | Print current line number with trailing new line, see sed example: line number |
b | Start next cycle |
b label | Jump to label (see :label ) |
d | delete pattern space |
D | |
e | execute pattern space as command and replace pattern-space with the command's output. |
e command | fill Pattern space with output of command. |
F | Print the current input file name. |
g | Copy Hold space into Pattern space. |
G | Add newline and Hold space to Pattern space. |
h | Copy Pattern space into Hold space. |
H | Add newline and Pattern space to Hold space. |
l , ln | Print pattern space (line length: n ). Non printable characters escaped in C style fashion. |
L | |
L n | |
N | |
p | print Pattern space to stdout. Usually used with (-n command line option). |
P | Print Pattern space up to first new line. |
q exit-code | Prints Pattern space (unless -n is used and exits with exit-code). Requires exactly one address. |
Q | |
r filename | |
R | |
s/regexp/replacement/flags | Substitute regexp with replacement in Pattern space. |
t | |
t label | |
T label | |
v version | fail if sed's version is lower than version (minimum: 4.0) |
w filename | write Pattern space to filename. When sed is started filename is created or truncated, then appended to. |
x | Exchange content of Pattern space and Hold space. |
y/source-chars/dest-chars | Replace characters in Pattern space (n-th source-char becomes n-th dest-char). (Called «transliteration»?) |
z | Empty Pattern space. More efficient and robust than s/.*// . |
{ command-1 command-2 ... command-n } | group multiple commands for an address or address range. |
:label | Introduce a location to which can be jumped to with b and t . |
n
: (n being a number) the n-th line. -s
flag is given. nfirst~nstep
: (nfirst and nstep being numbers): every nstep'th line, starting with nfirst. $
: last line. /regular-expression/
: each line that matches the given regular expression. \Cregular-expressionC
: same as above, C
being any character (that does not occur in regular-expression?) addr-one,addr-two
addr-two
is a regular expression, it won't be checked on the line where addr-one
matches. addr!command
!
is negated: it applies command on the «other» lines.