sed.1 (2010 09)
s
sed(1) sed(1)
NAME
sed - stream text editor
SYNOPSIS
sed [-n] script [file]...
sed [-n][-e script ]... [
-f script_file]... [file]...
DESCRIPTION
sed copies the named text files (standard input default) to the standard output, edited according to a
script containing up to 100 commands. Only complete input lines are processed. Any input text at the
end of a file that is not terminated by a new-line character is ignored.
Options
sed recognizes the following options:
-f script_file Take script from file script_file .
-e script Edit according to script . If there is just one
-e option and no -f options, the flag
-e can be omitted.
-n Suppress the default output.
sed interprets all -e script and -f script_file arguments in the order given. Use caution, if mixing
-e
and -f options, to avoid unpredictable or incorrect results.
Command Scripts
A script consists of editor commands, one per line, of the following form:
[ address [ , address ]] function [ arguments ]
In normal operation,
sed cyclically copies a line of input into a pattern space (unless there is something
left after a D command), applies in sequence all commands whose addresses select that pattern space,
and, at the end of the script, copies the pattern space to the standard output (except under
-n) and
deletes the pattern space.
Some of the commands use a hold space to save all or part of the pattern space for subsequent retrieval.
Command Addresses
An address is either a decimal number that counts input lines cumulatively across files, a
$ which
addresses the last line of input, or a context address; that is, a
/regular expression /
in the style of ed(1)
modified thus:
• In a context address, the construction
\?regular expression?
, where ? is any character, is identi-
cal to
/regular expression /. Note that in the context address \xabc\xdefx, the second
x
stands for itself, so that the regular expression is abcxdef.
• The escape sequence
\n matches a new-line character embedded in the pattern space.
• A period (
.) matches any character except the terminal new-line of the pattern space.
• A command line with no addresses selects every pattern space.
• A command line with one address selects each pattern space that matches the address.
• A command line with two addresses selects the inclusive range from the first pattern space that
matches the first address through the next pattern space that matches the second (if the second
address is a number less than or equal to the line number first selected, only one line is selected).
Thereafter the process is repeated, looking again for the first address.
sed supports Basic Regular Expression syntax (see regexp (5)).
Editing commands can also be applied to only non-selected pattern spaces by use of the negation function
! (described below).
Command Functions
In the following list of functions, the maximum number of permissible addresses for each function is indi-
cated in parentheses. Other function elements are interpreted as follows:
text One or more lines, all but the last of which end with \ to hide the new-line.
Backslashes in text are treated like backslashes in the replacement string of an s
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1