| www.delorie.com/gnu/docs/sed/sed_11.html | search |
![]() Buy the book! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
sed
These commands are specific to GNU sed, so you
must use them with care and only when you are sure that
hindering portability is not evil. They allow you to check
for GNU sed extensions or to do tasks that are required
quite often, yet are unsupported by standard seds.
e [command]
e command
executes the command that is found in pattern space and
replaces the pattern space with the output; a trailing new-line
is suppressed.
If a parameter is specified, instead, the e command
interprets it as a command and sends it to the output stream
(like r does). The command can run across multiple
lines, all but the last ending with a back-slash.
In both cases, the results are undefined if the command to be executed contains a NUL character.
L n
POSIXLY_CORRECT mode, this command only accepts a single
address.
This GNU sed extension fills and joins lines in pattern space
to produce output lines of (at most) n characters, like
fmt does; if n is omitted, the default as specified
on the command line is used.
Blank lines, spaces between words, and indentation are preserved in the output; successive input lines with different indentation are not joined; tabs are expanded to 8 columns.
If the pattern space contains multiple lines, they are joined, but
since the pattern space usually contains a single line, the behavior
of a simple L;d script is the same as `fmt -s' (i.e.,
it does not join short lines to form longer ones).
n specifies the desired line-wrap length; if omitted, the default as specified on the command line is used.
Q [exit-code]
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.
This command can be useful because the only alternative ways to accomplish this apparently trivial function are to use the `-n' option (which can unnecessarily complicate your script) or resorting to the following snippet, which wastes time by reading the whole file without any visible effect:
:eat $d Quit silently on the last line N Read another line, silently g Overwrite pattern space each time to save memory b eat |
R filename
As with the r command, the special value `/dev/stdin'
is supported for the file name, which reads a line from the
standard input.
T label
substitutions 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
sed fail if
GNU sed extensions are not supported, simply because other
versions of sed do not implement it.
W filename
w command about
file handling holds here too.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |