manpagez: man pages & more
info sed
Home | html | info | man

File: sed.info,  Node: sed commands list,  Next: The "s" Command,  Prev: sed script overview,  Up: sed scripts

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\’
‘TEXT’
     Append TEXT after a line.

‘a TEXT’
     Append TEXT after a line (alternative syntax).

‘b LABEL’
     Branch unconditionally to LABEL.  The LABEL may be omitted, in
     which case the next cycle is started.

‘c\’
‘TEXT’
     Replace (change) lines with TEXT.

‘c TEXT’
     Replace (change) lines with TEXT (alternative syntax).

‘d’
     Delete the pattern space; immediately start next cycle.

‘D’
     If 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.

‘e’
     Executes the command that is found in pattern space and replaces
     the pattern space with the output; a trailing newline is
     suppressed.

‘e COMMAND’
     Executes 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).

‘g’
     Replace the contents of the pattern space with the contents of the
     hold space.

‘G’
     Append 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.

‘H’
     Append 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\’
‘TEXT’
     insert TEXT before a line.

‘i TEXT’
     insert TEXT before a line (alternative syntax).

‘l’
     Print 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.

‘N’
     Add 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.

‘p’
     Print the pattern space.

‘P’
     Print the pattern space, up to the first .

‘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 filename’
     Reads file FILENAME.

‘R filename’
     Queue 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
     ‘s’ubstitution 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
     ‘s’ubstitutions 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 filename’
     Write the pattern space to FILENAME.

‘W filename’
     Write to the given filename the portion of the pattern space up to
     the first newline

‘x’
     Exchange 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).

‘: LABEL’
     Specify the location of LABEL for branch commands (‘b’, ‘t’, ‘T’).

© manpagez.com 2000-2026
Individual documents may contain additional copyright information.