(sed.info.gz) Invoking sed
(sed.info.gz) sed Programs
Normally `sed' is invoked like this:
sed SCRIPT INPUTFILE...
The full format for invoking `sed' is:
sed OPTIONS... [SCRIPT] [INPUTFILE...]
If you do not specify INPUTFILE, or if INPUTFILE is `-', `sed'
filters the contents of the standard input. The SCRIPT is actually the
first non-option parameter, which `sed' specially considers a script
and not an input file if (and only if) none of the other OPTIONS
specifies a script to be executed, that is if neither of the `-e' and
`-f' options is specified.
`sed' may be invoked with the following command-line options:
Print out the version of `sed' that is being run and a copyright
notice, then exit.
Print a usage message briefly summarizing these command-line
options and the bug-reporting address, then exit.
By default, `sed' prints out the pattern space at the end of each
cycle through the script. These options disable this automatic
printing, and `sed' only produces output when explicitly told to
via the `p' command.
This option specifies that files are to be edited in-place. GNU
`sed' does this by creating a temporary file and sending output to
this file rather than to the standard output.(1).
This option implies `-s'.
When the end of the file is reached, the temporary file is renamed
to the output file's original name. The extension, if supplied,
is used to modify the name of the old file before renaming the
temporary file, thereby making a backup copy(2)).
This rule is followed: if the extension doesn't contain a `*',
then it is appended to the end of the current filename as a
suffix; if the extension does contain one or more `*' characters,
then _each_ asterisk is replaced with the current filename. This
allows you to add a prefix to the backup file, instead of (or in
addition to) a suffix, or even to place backup copies of the
original files into another directory (provided the directory
If no extension is supplied, the original file is overwritten
without making a backup.
Specify the default line-wrap length for the `l' command. A
length of 0 (zero) means to never wrap long lines. If not
specified, it is taken to be 70.
GNU `sed' includes several extensions to POSIX sed. In order to
simplify writing portable scripts, this option disables all the
extensions that this manual documents, including additional
commands. Most of the extensions accept `sed' programs that are
outside the syntax mandated by POSIX, but some of them (such as
the behavior of the `N' command described in Reporting
Bugs) actually violate the standard. If you want to disable
only the latter kind of extension, you can set the
`POSIXLY_CORRECT' variable to a non-empty value.
Use extended regular expressions rather than basic regular
expressions. Extended regexps are those that `egrep' accepts;
they can be clearer because they usually have less backslashes,
but are a GNU extension and hence scripts that use them are not
portable. Extended regular expressions Extended regexps.
By default, `sed' will consider the files specified on the command
line as a single continuous long stream. This GNU `sed' extension
allows the user to consider them as separate files: range
addresses (such as `/abc/,/def/') are not allowed to span several
files, line numbers are relative to the start of each file, `$'
refers to the last line of each file, and files invoked from the
`R' commands are rewound at the start of each file.
Buffer both input and output as minimally as practical. (This is
particularly useful if the input is coming from the likes of `tail
-f', and you wish to see the transformed output as soon as
Add the commands in SCRIPT to the set of commands to be run while
processing the input.
Add the commands contained in the file SCRIPT-FILE to the set of
commands to be run while processing the input.
If no `-e', `-f', `--expression', or `--file' options are given on
the command-line, then the first non-option argument on the command
line is taken to be the SCRIPT to be executed.
If any command-line parameters remain after processing the above,
these parameters are interpreted as the names of input files to be
processed. A file name of `-' refers to the standard input stream.
The standard input will be processed if no file names are specified.
---------- Footnotes ----------
(1) This applies to commands such as `=', `a', `c', `i', `l', `p'.
You can still write to the standard output by using the `w' or `W'
commands together with the `/dev/stdout' special file
(2) Note that GNU `sed' creates the backup file whether or not
any output is actually changed.
(sed.info.gz) sed Programs
automatically generated byinfo2html