| www.delorie.com/gnu/docs/sed/sed_9.html | search |
![]() Buy the book! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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/
/ 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
POSIXLY_CORRECT mode, this command only accepts a single
address.
Queue the lines of text which follow this command
(each but the last ending with a \,
which are removed from the output)
to be output at the end of the current cycle,
or when the next input line is read.
As a GNU extension, if between the a and the newline there is
other than a whitespace-\ sequence, then the text of this line,
starting at the first non-whitespace character after the a,
is taken as the first line of the text block.
(This enables a simplification in scripting a one-line add.)
This extension also works with the i and c commands.
i\
text
POSIXLY_CORRECT mode, this command only accepts a single
address.
Immediately output the lines of text which follow this command
(each but the last ending with a \,
which are removed from the output).
c\
text
\,
which are 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.
=
POSIXLY_CORRECT mode, this command only accepts a single
address.
Print out the current input line number (with a trailing newline).
l n
\ 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 $.
n specifies the desired line-wrap length;
a length of 0 (zero) means to never wrap long lines. If omitted,
the default as specified on the command line is used. The n
parameter is a GNU sed extension.
r filename
POSIXLY_CORRECT mode, this command only accepts a single
address.
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.
As a GNU sed extension, the special value `/dev/stdin'
is supported for the file name, which reads the contents of the
standard input.
w filename
sed extension, two special values of file-name are
supported: `/dev/stderr', which writes the result to the standard
error, and `/dev/stdout', which writes to the standard
output.(4)
The file 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 without
closing and reopening the file.
D
N
sed exits without processing
any more commands.
P
h
H
g
G
x
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |