Home Explore Blog CI



man-pages

2nd chunk of `sed.man`
0505f3667a02c2c62662c2463c883e644037d7f2bb4e55400000000100000fe1
 version  3  or  later  <https://gnu.org/li‐
       censes/gpl.html>.  This is free software: you are free to change and re‐
       distribute it.  There is NO WARRANTY, to the extent permitted by law.

COMMAND SYNOPSIS
       This is just a brief synopsis of sed commands to serve as a reminder  to
       those  who  already  know  sed; other documentation (such as the texinfo
       document) must be consulted for fuller descriptions.

   Zero‐address ‘‘commands’’
       : label
              Label for b and t commands.

       #comment
              The comment extends until the next newline (or the end  of  a  -e
              script fragment).

       }      The closing bracket of a { } block.

   Zero‐ or One‐ address commands
       =      Print the current line number.

       a \

       text   Append  text, which has each embedded newline preceded by a back‐
              slash.

       i \

       text   Insert text, which has each embedded newline preceded by a  back‐
              slash.

       q [exit‐code]
              Immediately  quit  the sed script without processing any more in‐
              put, except that if auto‐print is not disabled the  current  pat‐
              tern  space will be printed.  The exit code argument is a GNU ex‐
              tension.

       Q [exit‐code]
              Immediately quit the sed script without processing any  more  in‐
              put.  This is a GNU extension.

       r filename
              Append text read from filename.

       R filename
              Append a line read from filename.  Each invocation of the command
              reads a line from the file.  This is a GNU extension.

   Commands which accept address ranges
       {      Begin a block of commands (end with a }).

       b label
              Branch to label; if label is omitted, branch to end of script.

       c \

       text   Replace  the  selected  lines  with text, which has each embedded
              newline preceded by a backslash.

       d      Delete pattern space.  Start next cycle.

       D      If pattern space contains no newline, start a normal new cycle as
              if the d command was issued.  Otherwise, delete text in the  pat‐
              tern  space  up  to the first newline, and restart cycle with the
              resultant pattern space, without reading a new line of input.

       h H    Copy/append pattern space to hold space.

       g G    Copy/append hold space to pattern space.

       l      List out the current line in a ‘‘visually unambiguous’’ form.

       l width
              List out the current line in  a  ‘‘visually  unambiguous’’  form,
              breaking it at width characters.  This is a GNU extension.

       n N    Read/append the next line of input into the pattern space.

       p      Print the current pattern space.

       P      Print  up  to  the  first embedded newline of the current pattern
              space.

       s/regexp/replacement/
              Attempt to match regexp against the pattern space.   If  success‐
              ful, replace that portion matched with replacement.  The replace‐
              ment may contain the special character & to refer to that portion
              of  the  pattern  space which matched, and the special escapes \1
              through \9 to refer to the corresponding matching sub‐expressions
              in the regexp.

       t label
              If a s/// has done a successful substitution since the last input
              line was read and since the last t or T command, then  branch  to
              label; if label is omitted, branch to end of script.

       T label
              If  no s/// has done a successful substitution since the last in‐
              put line was read and since the last t or T command, then  branch
              to  label; if label is omitted, branch to end of script.  This is
              a GNU extension.

       w filename
              Write the current

Title: SED Command Synopsis Continued: Addresses and Command Ranges
Summary
This section continues the synopsis of `sed` commands, detailing zero-address, one-address, and commands that accept address ranges. It includes commands for quitting the script, appending text from files, branching to labels, replacing lines, deleting pattern space content, manipulating hold space, listing lines, reading/appending input lines, printing pattern space, and performing substitutions using regular expressions. It also covers conditional branching based on successful substitutions and writing pattern space content to a file.