Next: The "s" Command, Previous: sed script overview, Up: sed scripts [Contents][Index]
sed commands summaryThe following commands are supported in GNU sed.
Some are standard POSIX commands, while other are GNU extensions.
Details and examples for each command are in the following sections.
(Mnemonics) are shown in parentheses.
a\textAppend text after a line.
a textAppend text after a line (alternative syntax).
b labelBranch unconditionally to label. The label may be omitted, in which case the next cycle is started.
c\textReplace (change) lines with text.
c textReplace (change) lines with text (alternative syntax).
dDelete the pattern space; immediately start next cycle.
DIf pattern space contains newlines, delete text in the pattern space up to the first newline, and restart cycle with the resultant pattern space, without reading a new line of input.
If pattern space contains no newline, start a normal new cycle as if
the d command was issued.
eExecutes the command that is found in pattern space and replaces the pattern space with the output; a trailing newline is suppressed.
e commandExecutes command and sends its output to the output stream. The command can run across multiple lines, all but the last ending with a back-slash.
F(filename) Print the file name of the current input file (with a trailing newline).
gReplace the contents of the pattern space with the contents of the hold space.
GAppend a newline to the contents of the pattern space, and then append the contents of the hold space to that of the pattern space.
h(hold) Replace the contents of the hold space with the contents of the pattern space.
HAppend a newline to the contents of the hold space, and then append the contents of the pattern space to that of the hold space.
i\textinsert text before a line.
i textinsert text before a line (alternative syntax).
lPrint the pattern space in an unambiguous form.
n(next) If auto-print is not disabled, print the pattern space,
then, regardless, replace the pattern space with the next line of input.
If there is no more input then sed exits without processing
any more commands.
NAdd a newline to the pattern space,
then append the next line of input to the pattern space.
If there is no more input then sed exits without processing
any more commands.
pPrint the pattern space.
PPrint the pattern space, up to the first <newline>.
q[exit-code](quit) Exit sed without processing any more commands or input.
Q[exit-code](quit) This command is the same as q, but will not print the
contents of pattern space. Like q, it provides the
ability to return an exit code to the caller.
r filenameReads file filename.
R filenameQueue a line of filename to be read and inserted into the output stream at the end of the current cycle, or when the next input line is read.
s/regexp/replacement/[flags](substitute) Match the regular-expression against the content of the pattern space. If found, replace matched string with replacement.
t label(test) Branch to label only if there has been a successful
substitution since the last input line was read or conditional
branch was taken. The label may be omitted, in which case the
next cycle is started.
T label(test) Branch to label only if there have been no successful
substitutions since the last input line was read or
conditional branch was taken. The label may be omitted,
in which case the next cycle is started.
v [version](version) This command does nothing, but makes sed fail if
GNU sed extensions are not supported, or if the requested version
is not available.
w filenameWrite the pattern space to filename.
W filenameWrite to the given filename the portion of the pattern space up to the first newline
xExchange the contents of the hold and pattern spaces.
y/src/dst/Transliterate any characters in the pattern space which match any of the source-chars with the corresponding character in dest-chars.
z(zap) This command empties the content of pattern space.
#A comment, until the next newline.
{ cmd ; cmd ... }Group several commands together.
=Print the current input line number (with a trailing newline).
: labelSpecify the location of label for branch commands (b,
t, T).
Next: The "s" Command, Previous: sed script overview, Up: sed scripts [Contents][Index]