GNU Info

Info Node: (sed.info)Other Commands

(sed.info)Other Commands


Next: Programming Commands Prev: Common Commands Up: sed Programs
Enter node , (file) or (file)node

Less frequently used commands
=============================

   Though perhaps less frequently used than those in the previous
section, some very small yet useful SED scripts can be built with these
commands.

`y/SOURCE-CHARS/DEST-CHARS/'
     (The `/' characters may be uniformly replaced by any other single
     character within any given `y' command.)

     Transliterate any characters in the pattern space which match any
     of the SOURCE-CHARS with the corresponding character in DEST-CHARS.

     Instances of the `/' (or whatever other character is used in its
     stead), `\', or newlines can appear in the SOURCE-CHARS or
     DEST-CHARS lists, provide that each instance is escaped by a `\'.
     The SOURCE-CHARS and DEST-CHARS lists _must_ contain the same
     number of characters (after de-escaping).

`a\'
`TEXT'
     [At most one address allowed.]

     Queue the lines of text which follow this command (each but the
     last ending with a `\', which will be removed from the output) to
     be output at the end of the current cycle, or when the next input
     line is read.

`i\'
`TEXT'
     [At most one address allowed.]

     Immediately output the lines of text which follow this command
     (each but the last ending with a `\', which will be removed from
     the output).

`c\'
`TEXT'
     Delete the lines matching the address or address-range, and output
     the lines of text which follow this command (each but the last
     ending with a `\', which will be removed from the output) in place
     of the last line (or in place of each line, if no addresses were
     specified).  A new cycle is started after this command is done,
     since the pattern space will have been deleted.

`='
     [At most one address allowed.]

     Print out the current input line number (with a trailing newline).

`l'
     Print the pattern space in an unambiguous form: non-printable
     characters (and the `\' character) are printed in C-style escaped
     form; long lines are split, with a trailing `\' character to
     indicate the split; the end of each line is marked with a `$'.

`r FILENAME'
     [At most one address allowed.]

     Queue the contents 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.  Note that if FILENAME cannot be read, it is
     treated as if it were an empty file, without any error indication.

`w FILENAME'
     Write the pattern space to FILENAME.  The FILENAME will be created
     (or truncated) before the first input line is read; all `w'
     commands (including instances of `w' flag on successful `s'
     commands) which refer to the same FILENAME are output through the
     same FILE stream.

`D'
     Delete text in the pattern space up to the first newline.  If any
     text is left, restart cycle with the resultant pattern space
     (without reading a new line of input), otherwise start a normal
     new cycle.

`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 out the portion of the pattern space up to the first newline.

`h'
     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.

`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.

`x'
     Exchange the contents of the hold and pattern spaces.


automatically generated by info2www version 1.2.2.9