sed commands list (sed, a stream editor)
Next: The "s" Command, Previous: sed script overview, Up: sed scripts [Contents][Index]
3.2 sed commands summary
The 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
textafter a line.a textAppend
textafter a line (alternative syntax).b labelBranch unconditionally to
label. Thelabelmay 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
dcommand 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
commandand 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
textbefore a line.i textinsert
textbefore 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
sedexits 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
sedexits without processing any more commands.pPrint the pattern space.
PPrint the pattern space, up to the first .
q[exit-code](quit) Exit
sedwithout 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. Likeq, it provides the ability to return an exit code to the caller.r filenameReads file
filename.R filenameQueue a line of
filenameto 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
labelonly if there has been a successfulsubstitution since the last input line was read or conditional branch was taken. Thelabelmay be omitted, in which case the next cycle is started.T label(test) Branch to
labelonly if there have been no successfulsubstitutions since the last input line was read or conditional branch was taken. Thelabelmay be omitted, in which case the next cycle is started.v [version](version) This command does nothing, but makes
sedfail if GNUsedextensions 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-charswith the corresponding character indest-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
labelfor branch commands (b,t,T).
Next: The "s" Command, Previous: sed script overview, Up: sed scripts [Contents][Index]