Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)

sed(1) OSS Shell and Utilities Reference Manual
NAME
sed - Provides a stream line editor
SYNOPSIS
sed [-n][-e escript] ... [-f script_file] ... [file ...]
sed [-n] script [file ...]
The sed command modifies lines from the specified file or from standard input according to
edit commands and writes them to standard output.
FLAGS
-e escript
Uses the string escript as an edit script. If you are using just one -e flag and no -f ag,
you can omit the -e flag and include the single escript on the command line as an argu-
ment to sed.
-f script_file
Uses script_file as the source of the edit script. The script_file is a set of editing com-
mands to be applied to file.
-n Suppresses the default action of writing each line to standard output after editing. Only
lines explicitly selected for output are written.
DESCRIPTION
The sed command includes many features for selecting lines to be modified and making changes
only to the selected lines.
The sed command uses two workspaces for holding the line being modified: the pattern space,
where the selected line is held, and the hold space, where lines can be stored temporarily.
An edit script consists of individual subcommands, each one on a separate line. The general
form of sed subcommands is as follows:
[address[,address]] command [argument ...]
The sed command processes each input file by reading an input line into the pattern space,
sequentially applying all sed subcommands in sequence whose addresses select that pattern
space, and writing the pattern space to standard output. It then clears the pattern space and
repeats this process for each line in the input file. Some of the subcommands use a hold space to
save all or part of the pattern space for subsequent retrieval.
When a command includes an address, either a line number or a search pattern, only the
addressed line or lines are affected by the command. Otherwise, the command is applied to all
lines.
The sed Addresses
An address is either a decimal line number, a $, which addresses the last line of input, or a con-
text address. A context address is a regular expression as described for grep, except that you can
select the character delimiter for patterns. The general form of the expression is as follows:
\?pattern\?
The ? represents a character delimiter you select. This delimiter cannot be a multibyte character.
The default form for the pattern is as follows:
/pattern/
In a context address, the construction \cexpressionc, where c is any character other than
a \ (backslash) or the newline character, is identical to /expression/. If the character
designated by c appears following a \ (backslash), then it is considered to be that literal
82 Hewlett-Packard Company 527188-007