|
|
coherent
sed Command sed
Stream editor
sseedd [ -nn ] [-ee _c_o_m_m_a_n_d_s] [-ff _s_c_r_i_p_t] ... _f_i_l_e ...
sed is a non-interactive text editor. It reads input from each
file, or from the standard input if no file is named. It edits
the input according to commands given in the commands argument
and the script files. It then writes the edited text onto the
standard output.
sed resembles the interactive editor ed, but its operation is
fundamentally different. sed normally edits one line at a time,
so it may be used to edit very large files. After it constructs
a list of commands from its commands and script arguments, sed
reads the input one line at a time into a work area. Then sed
executes each command that applies to the line, as explained
below. Finally, it copies the work area to the standard output
(unless the -n option is specified), erases the work area, and
reads the next input line.
***** Line Identifiers *****
sed identifies input lines by integer line numbers, beginning
with one for the first line of the first file and continuing
through each successive file. The following special forms iden-
tify lines:
nn A decimal number n addresses the nth line of the input.
. A period `.' addresses the current input line.
$ A dollar sign `$' addresses the last line of input.
/ppaatttteerrnn/
A pattern enclosed within slashes addresses the next input
line that contains pattern. Patterns, also called regular
expressions, are described in detail below.
***** Commands *****
Each command must be on a separate line. Most commands may be
optionally preceded by a line identifier (abbreviated as [n] in
the command summary below) or by two-line identifiers separated
by a comma (abbreviated as [n[,m]]). If no line identifier
precedes a command, sed applies the command to every input line.
If one line identifier precedes a command, sed applies the com-
mand to each input line selected by the identifier. If two-line
identifiers precede a command, sed begins to apply the command
when an input line is selected by the first, and continues ap-
plying it through an input line selected by the second.
sed recognizes the following commands:
COHERENT Lexicon Page 1
sed Command sed
[_n]= Output the current input line number.
[_n[,_m]]!_c_o_m_m_a_n_d
Apply command to each line not identified by [n[,m]].
[_n[,_m]]{_c_o_m_m_a_n_d...}
Execute each enclosed command on the given lines.
:_l_a_b_e_l
Define label for use in branch or test command.
[_n]aa\
Append new text after given line. New text is terminated by
any line not ending in `\'.
bb [_l_a_b_e_l]
Branch to label, which must be defined in a `:' command. If
label is omitted, branch to end of command script.
[_n[,_m]]cc\
Change specified lines to new text and proceed with next in-
put line. New text is terminated by any line not ending in
`\'.
[_n[,_m]]dd
Delete specified lines and proceed with next input line.
[_n[,_m]]DD
Delete first line in work area and proceed with next input
line.
[_n[,_m]]gg
Copy secondary work area to work area, destroying previous
contents.
[_n[,_m]]GG
Append secondary work area to work area.
[_n[,_m]]hh
Copy work area to secondary work area, destroying previous
contents.
[_n[,_m]]HH
Append work area to secondary work area.
[_n]ii\
Insert new text before given line. New text is terminated
by any line not ending in `\'.
[_n[,_m]]ll
Print selected lines, interpreting non-graphic characters.
[_n[,_m]]nn
Print the work area and replace it with the next input line.
COHERENT Lexicon Page 2
sed Command sed
[_n[,_m]]NN
Append next input line preceded by a newline to work area.
[_n[,_m]]pp
Print work area.
[_n[,_m]]PP
Print first line of work area.
[_n]qq Quit without reading any more input.
[_n]rr _f_i_l_e
Copy file to output.
[_n[,_m]]ss[_k]/_p_a_t_t_e_r_n_1/_p_a_t_t_e_r_n_2/[gg][pp][ww _f_i_l_e]
Search for pattern1 and substitute pattern2 for kth occur-
rence (default, first). If optional g is given, substitute
all occurrences. If optional p is given, print the resul-
ting line. If optional w is given, append the resulting
line to file. Patterns are described in detail below.
[_n[,_m]]tt[_l_a_b_e_l]
Test if substitutions have been made. If so, branch to
label, which must be defined in a `:' command. If label is
omitted, branch to end of command script.
[_n[,_m]]ww _f_i_l_e
Append lines to file.
[_n[,_m]] xx
Exchange the work area and the secondary work area.
[_n[,_m]]yy/_c_h_a_r_s/_r_e_p_l_a_c_e_m_e_n_t_s/
Translate characters in chars to the corresponding charac-
ters in replacements.
***** Patterns *****
Substitution commands and search specifications may include pat-
terns, also called regular expressions. Pattern specifications
are identical to those of ed, except that the special characters
`\nn' match a newline character in the input.
A non-special character in a pattern matches itself. Special
characters include the following:
^ Match beginning of line, unless it appears immediately after
`[' (see below).
$ Match end of line.
\nn Match the newline character.
. Match any character except newline.
COHERENT Lexicon Page 3
sed Command sed
* Match zero or more repetitions of preceding character.
[_c_h_a_r_s]
Match any one of the enclosed chars. Ranges of letters or
digits may be indicated using `-'.
[^_c_h_a_r_s]
Match any character except one of the enclosed chars. Ran-
ges of letters or digits may be indicated using `-'.
\_c Disregard special meaning of character c.
\(_p_a_t_t_e_r_n\)
Delimit substring pattern; for use with \_d, described below.
In addition, the replacement part pattern2 of the substitute com-
mand may also use the following:
& Insert characters matched by pattern1.
\_d Insert substring delimited by dth occurrence of delimiters
`\(' and `\)', where d is a digit.
***** Options *****
sed recognizes the following options:
-ee Next argument gives commands.
-ff Next argument gives file name of command script.
-nn Output lines only when explicit p or P commands are given.
***** See Also *****
commands, ed
COHERENT Lexicon Page 4
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.