Home Explore Blog CI



man-pages

3rd chunk of `sed.man`
c5fe50a6359c6c6f3d110be55c13a8b0df38e501b5555c110000000100000b4b
     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 pattern space to filename.

       W filename
              Write the first line of the current pattern  space  to  filename.
              This is a GNU extension.

       x      Exchange the contents of the hold and pattern spaces.

       y/source/dest/
              Transliterate the characters in the pattern space which appear in
              source to the corresponding character in dest.

Addresses
       Sed  commands  can be given with no addresses, in which case the command
       will be executed for all input lines; with one address,  in  which  case
       the  command  will only be executed for input lines which match that ad‐
       dress; or with two addresses, in which case the command will be executed
       for all input lines which match the inclusive range  of  lines  starting
       from  the  first  address  and  continuing to the second address.  Three
       things to note about address ranges: the syntax  is  addr1,addr2  (i.e.,
       the  addresses  are  separated by a comma); the line which addr1 matched
       will always be accepted, even if addr2 selects an earlier line;  and  if
       addr2  is  a  regexp,  it will not be tested against the line that addr1
       matched.

       After the address (or address‐range), and before the command, a  !   may
       be  inserted, which specifies that the command shall only be executed if
       the address (or address‐range) does not match.

       The following address types are supported:

       number Match only the specified line number  (which  increments  cumula‐
              tively  across  files,  unless  the -s option is specified on the
              command line).

       first~step
              Match every step’th line starting with line first.  For  example,
              ‘‘sed  -n 1~2p’’ will print all the odd‐numbered lines in the in‐

Title: SED Command Synopsis Continued: Substitution, Branching, Writing, and Addressing
Summary
This section of the `sed` command synopsis details the substitution command (`s/regexp/replacement/`), conditional branching commands (`t` and `T`), writing to file commands (`w` and `W`), exchange hold and pattern spaces (`x`), and transliteration (`y/source/dest/`). It then explains addressing in `sed`, including no addresses (all lines), single addresses (matching lines), and address ranges (inclusive range of lines). The `!` can be used to negate the address match. It also covers different address types: line numbers and step intervals.