version 1.20, 2004/01/23 23:08:47 |
version 1.21, 2004/01/29 21:19:04 |
|
|
The form of a |
The form of a |
.Nm |
.Nm |
command is as follows: |
command is as follows: |
.sp |
.Pp |
.Dl [address[,address]]function[arguments] |
.Dl [address[,address]]function[arguments] |
.sp |
.Pp |
Whitespace may be inserted before the first address and the function |
Whitespace may be inserted before the first address and the function |
portions of the command. |
portions of the command. |
.Pp |
.Pp |
|
|
.Nm |
.Nm |
cyclically copies a line of input, not including its terminating newline |
cyclically copies a line of input, not including its terminating newline |
character, into a |
character, into a |
.Em "pattern space" , |
.Em pattern space , |
(unless there is something left after a |
(unless there is something left after a |
.Sq D |
.Sq D |
function), |
function), |
|
|
deletes the pattern space. |
deletes the pattern space. |
.Pp |
.Pp |
Some of the functions use a |
Some of the functions use a |
.Em "hold space" |
.Em hold space |
to save all or part of the pattern space for subsequent retrieval. |
to save all or part of the pattern space for subsequent retrieval. |
.Sh "Sed Addresses" |
.Sh SED ADDRESSES |
An address is not required, but if specified must be a number (that counts |
An address is not required, but if specified must be a number (that counts |
input lines |
input lines |
cumulatively across input files), a dollar |
cumulatively across input files), a dollar character |
.Pq Ql $ |
.Pq Ql $ |
character that addresses the last line of input, or a context address |
that addresses the last line of input, or a context address |
(which consists of a regular expression preceded and followed by a |
(which consists of a regular expression preceded and followed by a |
delimiter). |
delimiter). |
.Pp |
.Pp |
|
|
of the exclamation character |
of the exclamation character |
.Pq Ql \&! |
.Pq Ql \&! |
function. |
function. |
.Sh "Sed Regular Expressions" |
.Sh SED REGULAR EXPRESSIONS |
The |
The |
.Nm |
.Nm |
regular expressions are basic regular expressions (BRE's, see |
regular expressions are basic regular expressions (BRE's; see |
.Xr re_format 7 |
.Xr re_format 7 |
for more information). |
for more information). |
In addition, |
In addition, |
.Nm |
.Nm |
has the following two additions to BRE's: |
has the following two additions to BRE's: |
.sp |
.Pp |
.Bl -enum -compact |
.Bl -enum -compact |
.It |
.It |
In a context address, any character other than a backslash |
In a context address, any character other than a backslash |
|
|
.Sq x |
.Sq x |
stands for itself, so that the regular expression is |
stands for itself, so that the regular expression is |
.Dq abcxdef . |
.Dq abcxdef . |
.sp |
.Pp |
.It |
.It |
The escape sequence \en matches a newline character embedded in the |
The escape sequence \en matches a newline character embedded in the |
pattern space. |
pattern space. |
|
|
.Dq XXX |
.Dq XXX |
for the pattern |
for the pattern |
.Dq abc . |
.Dq abc . |
.Sh "Sed Functions" |
.Sh SED FUNCTIONS |
In the following list of commands, the maximum number of permissible |
In the following list of commands, the maximum number of permissible |
addresses for each command is indicated by [0addr], [1addr], or [2addr], |
addresses for each command is indicated by [0addr], [1addr], or [2addr], |
representing zero, one, or two addresses. |
representing zero, one, or two addresses. |
|
|
The terminating |
The terminating |
.Ql } |
.Ql } |
must be preceded by a newline or optional whitespace. |
must be preceded by a newline or optional whitespace. |
.sp |
.Pp |
.Bl -tag -width "XXXXXX" -compact |
.Bl -tag -width "XXXXXXXX" -compact |
.It [2addr] Em function-list |
.It [2addr] Em function-list |
Execute |
Execute |
.Em function-list |
.Em function-list |
only when the pattern space is selected. |
only when the pattern space is selected. |
.sp |
.Pp |
.It [1addr] Ns Em a Ns \e |
.It [1addr] Ns Em a Ns \e |
.It Em text |
.It Em text |
.br |
.Pp |
Write |
Write |
.Em text |
.Em text |
to standard output immediately before each attempt to read a line of input, |
to standard output immediately before each attempt to read a line of input, |
whether by executing the |
whether by executing the |
.Sq N |
.Sq N |
function or by beginning a new cycle. |
function or by beginning a new cycle. |
.sp |
.Pp |
.It [2addr] Ns Em b Ns [label] |
.It [2addr] Ns Em b Ns [label] |
Branch to the |
Branch to the |
.Sq \&: |
.Sq \&: |
function with the specified label. |
function with the specified label. |
If the label is not specified, branch to the end of the script. |
If the label is not specified, branch to the end of the script. |
.sp |
.Pp |
.It [2addr] Ns Em c Ns \e |
.It [2addr] Ns Em c Ns \e |
.It Em text |
.It Em text |
.br |
.Pp |
Delete the pattern space. |
Delete the pattern space. |
With 0 or 1 address or at the end of a 2-address range, |
With 0 or 1 address or at the end of a 2-address range, |
.Em text |
.Em text |
is written to the standard output. |
is written to the standard output. |
.sp |
.Pp |
.It [2addr] Ns Em d |
.It [2addr] Ns Em d |
Delete the pattern space and start the next cycle. |
Delete the pattern space and start the next cycle. |
.sp |
.Pp |
.It [2addr] Ns Em D |
.It [2addr] Ns Em D |
Delete the initial segment of the pattern space through the first |
Delete the initial segment of the pattern space through the first |
newline character and start the next cycle. |
newline character and start the next cycle. |
.sp |
.Pp |
.It [2addr] Ns Em g |
.It [2addr] Ns Em g |
Replace the contents of the pattern space with the contents of the |
Replace the contents of the pattern space with the contents of the |
hold space. |
hold space. |
.sp |
.Pp |
.It [2addr] Ns Em G |
.It [2addr] Ns Em G |
Append a newline character followed by the contents of the hold space |
Append a newline character followed by the contents of the hold space |
to the pattern space. |
to the pattern space. |
.sp |
.Pp |
.It [2addr] Ns Em h |
.It [2addr] Ns Em h |
Replace the contents of the hold space with the contents of the |
Replace the contents of the hold space with the contents of the |
pattern space. |
pattern space. |
.sp |
.Pp |
.It [2addr] Ns Em H |
.It [2addr] Ns Em H |
Append a newline character followed by the contents of the pattern space |
Append a newline character followed by the contents of the pattern space |
to the hold space. |
to the hold space. |
.sp |
.Pp |
.It [1addr] Ns Em i Ns \e |
.It [1addr] Ns Em i Ns \e |
.It Em text |
.It Em text |
.br |
.Pp |
Write |
Write |
.Em text |
.Em text |
to the standard output. |
to the standard output. |
.sp |
.Pp |
.It [2addr] Ns Em l |
.It [2addr] Ns Em l |
(The letter ell.) |
(The letter ell.) |
Write the pattern space to the standard output in a visually unambiguous |
Write the pattern space to the standard output in a visually unambiguous |
form. |
form. |
This form is as follows: |
This form is as follows: |
.sp |
.Pp |
.Bl -tag -width "carriage-returnXX" -offset indent -compact |
.Bl -tag -width "carriage-returnXX" -offset indent -compact |
.It backslash |
.It backslash |
\e\e |
\e\e |
|
|
a backslash followed by a newline. |
a backslash followed by a newline. |
The end of each line is marked with a |
The end of each line is marked with a |
.Ql $ . |
.Ql $ . |
.sp |
.Pp |
.It [2addr] Ns Em n |
.It [2addr] Ns Em n |
Write the pattern space to the standard output if the default output has |
Write the pattern space to the standard output if the default output has |
not been suppressed, and replace the pattern space with the next line of |
not been suppressed, and replace the pattern space with the next line of |
input. |
input. |
.sp |
.Pp |
.It [2addr] Ns Em N |
.It [2addr] Ns Em N |
Append the next line of input to the pattern space, using an embedded |
Append the next line of input to the pattern space, using an embedded |
newline character to separate the appended material from the original |
newline character to separate the appended material from the original |
contents. |
contents. |
Note that the current line number changes. |
Note that the current line number changes. |
.sp |
.Pp |
.It [2addr] Ns Em p |
.It [2addr] Ns Em p |
Write the pattern space to standard output. |
Write the pattern space to standard output. |
.sp |
.Pp |
.It [2addr] Ns Em P |
.It [2addr] Ns Em P |
Write the pattern space, up to the first newline character to the |
Write the pattern space, up to the first newline character to the |
standard output. |
standard output. |
.sp |
.Pp |
.It [1addr] Ns Em q |
.It [1addr] Ns Em q |
Branch to the end of the script and quit without starting a new cycle. |
Branch to the end of the script and quit without starting a new cycle. |
.sp |
.Pp |
.It [1addr] Ns Em r file |
.It [1addr] Ns Em r file |
Copy the contents of |
Copy the contents of |
.Em file |
.Em file |
|
|
.Em file |
.Em file |
cannot be read for any reason, it is silently ignored and no error |
cannot be read for any reason, it is silently ignored and no error |
condition is set. |
condition is set. |
.sp |
.Pp |
.It [2addr] Ns Em s Ns /re/replacement/flags |
.It [2addr] Ns Em s Ns /re/replacement/flags |
Substitute the replacement string for the first instance of the regular |
Substitute the replacement string for the first instance of the regular |
expression in the pattern space. |
expression in the pattern space. |
|
|
.Em flags |
.Em flags |
in the substitute function is zero or more of the following: |
in the substitute function is zero or more of the following: |
.Bl -tag -width "XXXXXX" -offset indent |
.Bl -tag -width "XXXXXX" -offset indent |
.It "0 ... 9" |
.It 0 ... 9 |
Make the substitution only for the N'th occurrence of the regular |
Make the substitution only for the N'th occurrence of the regular |
expression in the pattern space. |
expression in the pattern space. |
.It g |
.It g |
|
|
If the replacement string is identical to that which it replaces, it |
If the replacement string is identical to that which it replaces, it |
is still considered to have been a replacement. |
is still considered to have been a replacement. |
.El |
.El |
.sp |
.Pp |
.It [2addr] Ns Em t Ns [label] |
.It [2addr] Ns Em t Ns [label] |
Branch to the |
Branch to the |
.Ql \&: |
.Ql \&: |
|
|
.Sq t |
.Sq t |
function. |
function. |
If no label is specified, branch to the end of the script. |
If no label is specified, branch to the end of the script. |
.sp |
.Pp |
.It [2addr] Ns Em w file |
.It [2addr] Ns Em w file |
Append the pattern space to the |
Append the pattern space to the |
.Em file . |
.Em file . |
.sp |
.Pp |
.It [2addr] Ns Em x |
.It [2addr] Ns Em x |
Swap the contents of the pattern and hold spaces. |
Swap the contents of the pattern and hold spaces. |
.sp |
.Pp |
.It [2addr] Ns Em y Ns /string1/string2/ |
.It [2addr] Ns Em y Ns /string1/string2/ |
Replace all occurrences of characters in |
Replace all occurrences of characters in |
.Em string1 |
.Em string1 |
|
|
character, and a backslash followed by an |
character, and a backslash followed by an |
.Sq n |
.Sq n |
is replaced by a newline character. |
is replaced by a newline character. |
.sp |
.Pp |
.Sm off |
.Sm off |
.It Xo [2addr] Em !function No ,\ [2addr] |
.It Xo [2addr] Em !function No ,\ \&[2addr] |
.Em !function-list |
.Em !function-list |
.Xc |
.Xc |
.Sm on |
.Sm on |
Apply the function or function-list only to the lines that are |
Apply the function or function-list only to the lines that are |
.Em not |
.Em not |
selected by the address(es). |
selected by the address(es). |
.sp |
.Pp |
.It [0addr] Ns Em : Ns label |
.It [0addr] Ns Em \&: Ns label |
This function does nothing; it bears a label to which the |
This function does nothing; it bears a label to which the |
.Sq b |
.Sq b |
and |
and |
.Sq t |
.Sq t |
commands may branch. |
commands may branch. |
.sp |
.Pp |
.It [1addr] Ns Em = |
.It [1addr] Ns Em = |
Write the line number to the standard output followed by a newline character. |
Write the line number to the standard output followed by a newline character. |
.sp |
.Pp |
.It [0addr] |
.It [0addr] |
Empty lines are ignored. |
Empty lines are ignored. |
.sp |
.Pp |
.It [0addr] Ns Em # |
.It [0addr] Ns Em # |
The |
The |
.Ql # |
.Ql # |
|
|
.Xr grep 1 , |
.Xr grep 1 , |
.Xr regex 3 , |
.Xr regex 3 , |
.Xr re_format 7 |
.Xr re_format 7 |
|
.Pp |
|
.Pa /usr/share/doc/usd/15.sed/ |
.Sh STANDARDS |
.Sh STANDARDS |
The |
The |
.Nm |
.Nm |