mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-11-18 19:09:31 +00:00
99e3b1cd28
to be reviewed; there are still problems with it.
481 lines
14 KiB
Groff
481 lines
14 KiB
Groff
.\" Copyright (c) 1992, 1993
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
.\"
|
|
.\" This code is derived from software contributed to Berkeley by
|
|
.\" the Institute of Electrical and Electronics Engineers, Inc.
|
|
.\"
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
.\" modification, are permitted provided that the following conditions
|
|
.\" are met:
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
.\" must display the following acknowledgement:
|
|
.\" This product includes software developed by the University of
|
|
.\" California, Berkeley and its contributors.
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
.\" may be used to endorse or promote products derived from this software
|
|
.\" without specific prior written permission.
|
|
.\"
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
.\" SUCH DAMAGE.
|
|
.\"
|
|
.\" @(#)sed.1 8.2 (Berkeley) 12/30/93
|
|
.\"
|
|
.TH SED 1 "November 1997" "GNO" "Commands and Applications"
|
|
.SH NAME
|
|
.BR sed
|
|
\- stream editor
|
|
.SH SYNOPSIS
|
|
.BI sed " command"
|
|
.RB [ -an ]
|
|
.RI [ "file " ...]
|
|
.PP
|
|
.BR sed " [" -an ]
|
|
.RB [ -e
|
|
.IR command ]...
|
|
.RB [ -f
|
|
.IR command_file ]...
|
|
.RI [ "file " ...]
|
|
.SH DESCRIPTION
|
|
The
|
|
.BR sed
|
|
utility reads the specified files, or the standard input if no files
|
|
are specified, modifying the input as specified by a list of commands.
|
|
The input is then written to the standard output.
|
|
.PP
|
|
A single command may be specified as the first argument to
|
|
.BR sed .
|
|
Multiple commands may be specified by using the
|
|
.BR -e
|
|
or
|
|
.BR -f
|
|
options.
|
|
All commands are applied to the input in the order they are specified
|
|
regardless of their origin.
|
|
.PP
|
|
The following options are available:
|
|
.IP \fB-a\fR
|
|
The files listed as parameters for the
|
|
.BR w " (write)"
|
|
functions are created (or truncated) before any processing begins,
|
|
by default.
|
|
The
|
|
.BR -a
|
|
option causes
|
|
.BR sed
|
|
to delay opening each file until a command containing the related
|
|
.BR w
|
|
function is applied to a line of input.
|
|
.IP "\fB-e\fR \fIcommand\fR"
|
|
Append the editing commands specified by the
|
|
.BR command
|
|
argument
|
|
to the list of commands.
|
|
.IP "\fB-f\fR \fIcommand_file\fR"
|
|
Append the editing commands found in the file
|
|
.BR command_file
|
|
to the list of commands.
|
|
The editing commands should each be listed on a separate line.
|
|
.IP \fB-n\fR
|
|
By default, each line of input is echoed to the standard output after
|
|
all of the commands have been applied to it.
|
|
The
|
|
.BR -n
|
|
option suppresses this behavior.
|
|
.PP
|
|
The form of a
|
|
.BR sed
|
|
command is as follows:
|
|
.HP
|
|
.RI [ \|address
|
|
.RB [ \|,
|
|
.IR address\| ]\|]
|
|
.I function
|
|
.RI [ \|arguments\| ]
|
|
.PP
|
|
Whitespace may be inserted before the first address and the function
|
|
portions of the command.
|
|
.PP
|
|
Normally,
|
|
.BR sed
|
|
cyclically copies a line of input, not including its terminating newline
|
|
character, into a
|
|
.IR "pattern space" ,
|
|
(unless there is something left after a
|
|
.BR D
|
|
function),
|
|
applies all of the commands with addresses that select that pattern space,
|
|
copies the pattern space to the standard output, appending a newline, and
|
|
deletes the pattern space.
|
|
.PP
|
|
Some of the functions use a
|
|
.IR "hold space"
|
|
to save all or part of the pattern space for subsequent retrieval.
|
|
.SH "Sed Addresses"
|
|
An address is not required, but if specified must be a number (that counts
|
|
input lines
|
|
cumulatively across input files), a dollar
|
|
.RB ( $ )
|
|
character that addresses the last line of input, or a context address
|
|
(which consists of a regular expression preceded and followed by a
|
|
delimiter).
|
|
.PP
|
|
A command line with no addresses selects every pattern space.
|
|
.PP
|
|
A command line with one address selects all of the pattern spaces
|
|
that match the address.
|
|
.PP
|
|
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 that line is selected.)
|
|
Starting at the first line following the selected range,
|
|
.BR sed
|
|
starts looking again for the first address.
|
|
.PP
|
|
Editing commands can be applied to non-selected pattern spaces by use
|
|
of the exclamation character
|
|
.RB ( ! )
|
|
function.
|
|
.SH "Sed Regular Expressions"
|
|
The
|
|
.BR sed
|
|
regular expressions are basic regular expressions (BRE's, see
|
|
.BR regex (3)
|
|
for more information).
|
|
In addition,
|
|
.BR sed
|
|
has the following two additions to BRE's:
|
|
.HP
|
|
In a context address, any character other than a backslash
|
|
.RB ( \\\\ )
|
|
or newline character may be used to delimit the regular expression.
|
|
Also, putting a backslash character before the delimiting character
|
|
causes the character to be treated literally.
|
|
For example, in the context address \\xabc\\xdefx, the RE delimiter
|
|
is an
|
|
.BR x
|
|
and the second
|
|
.BR x
|
|
stands for itself, so that the regular expression is
|
|
.BR abcxdef .
|
|
.HP
|
|
The escape sequence \\n matches a newline character embedded in the
|
|
pattern space.
|
|
You can't, however, use a literal newline character in an address or
|
|
in the substitute command.
|
|
.PP
|
|
One special feature of
|
|
.BR sed
|
|
regular expressions is that they can default to the last regular
|
|
expression used.
|
|
If a regular expression is empty, i.e. just the delimiter characters
|
|
are specified, the last regular expression encountered is used instead.
|
|
The last regular expression is defined as the last regular expression
|
|
used as part of an address or substitute command, and at run-time, not
|
|
compile-time.
|
|
For example, the command
|
|
.BR /abc/s//XXX/
|
|
will substitute
|
|
.BR XXX
|
|
for the pattern
|
|
.BR abc .
|
|
.SH "Sed Functions"
|
|
In the following list of commands, the maximum number of permissible
|
|
addresses for each command is indicated by [0addr], [1addr], or [2addr],
|
|
representing zero, one, or two addresses.
|
|
.PP
|
|
The argument
|
|
.IR text
|
|
consists of one or more lines.
|
|
To embed a newline in the text, precede it with a backslash.
|
|
Other backslashes in text are deleted and the following character
|
|
taken literally.
|
|
.PP
|
|
The
|
|
.BR r
|
|
and
|
|
.BR w
|
|
functions take an optional file parameter, which should be separated
|
|
from the function letter by white space.
|
|
Each file given as an argument to
|
|
.BR sed
|
|
is created (or its contents truncated) before any input processing begins.
|
|
.PP
|
|
The
|
|
.BR b ,
|
|
.BR r ,
|
|
.BR s ,
|
|
.BR t ,
|
|
.BR w ,
|
|
.BR y ,
|
|
.BR ! ,
|
|
and
|
|
.BR \&:
|
|
functions all accept additional arguments.
|
|
The following synopses indicate which arguments have to be separated from
|
|
the function letters by white space characters.
|
|
.PP
|
|
Two of the functions take a function-list.
|
|
This is a list of
|
|
.BR sed
|
|
functions separated by newlines, as follows:
|
|
.IP
|
|
.nf
|
|
-literal -offset indent
|
|
{ function
|
|
function
|
|
...
|
|
function
|
|
}
|
|
.fi
|
|
.PP
|
|
The
|
|
.BR {
|
|
can be preceded by white space and can be followed by white space.
|
|
The function can be preceded by white space.
|
|
The terminating
|
|
.BR }
|
|
must be preceded by a newline or optional white space.
|
|
.IP [2addr]\fIfunction-list\fR
|
|
Execute function-list only when the pattern space is selected.
|
|
.PP
|
|
.RB [1addr] a\\\\
|
|
.IP \fItext\fR
|
|
Write
|
|
.IR text
|
|
to standard output immediately before each attempt to read a line of input,
|
|
whether by executing the
|
|
.BR N
|
|
function or by beginning a new cycle.
|
|
.IP "[2addr]\fBb\fR [label]\fR"
|
|
Branch to the
|
|
.BR \&:
|
|
function with the specified label.
|
|
If the label is not specified, branch to the end of the script.
|
|
.PP
|
|
.RB [2addr] c\\\\
|
|
.IP \fItext\fR
|
|
Delete the pattern space.
|
|
With 0 or 1 address or at the end of a 2-address range,
|
|
.IR text
|
|
is written to the standard output.
|
|
.IP [2addr]\fBd\fR
|
|
Delete the pattern space and start the next cycle.
|
|
.IP [2addr]\fBD\fR
|
|
Delete the initial segment of the pattern space through the first
|
|
newline character and start the next cycle.
|
|
.IP [2addr]\fBg\fR
|
|
Replace the contents of the pattern space with the contents of the
|
|
hold space.
|
|
.IP [2addr]\fBG\fR
|
|
Append a newline character followed by the contents of the hold space
|
|
to the pattern space.
|
|
.IP [2addr]\fBh\fR
|
|
Replace the contents of the hold space with the contents of the
|
|
pattern space.
|
|
.IP [2addr]\fBH\fR
|
|
Append a newline character followed by the contents of the pattern space
|
|
to the hold space.
|
|
.PP
|
|
.RB [1addr] i\\\\
|
|
.IP \fItext\fR
|
|
.br
|
|
Write
|
|
.IR text
|
|
to the standard output.
|
|
.IP [2addr]\fBl\fR
|
|
(The letter ell.)
|
|
Write the pattern space to the standard output in a visually unambiguous
|
|
form.
|
|
This form is as follows:
|
|
.RS
|
|
.nf
|
|
\fIbackslash\fR\0\0\0\0\0\0\0\fB\\\&\\\fR
|
|
\fIalert\fR\0\0\0\0\0\0\0\0\0\0\0\fB\\\&a\fR
|
|
\fIform-feed\fR\0\0\0\0\0\0\0\fB\\\&f\fR
|
|
\fInewline\fR\0\0\0\0\0\0\0\0\0\fB\\\&n\fR
|
|
\fIcarriage-return\fR\0\fB\\\&r\fR
|
|
\fItab\fR\0\0\0\0\0\0\0\0\0\0\0\0\0\fB\\\&t\fR
|
|
\fIvertical\0tab\fR\0\0\0\0\fB\\\&v\fR
|
|
.fi
|
|
.RE
|
|
.PP
|
|
Nonprintable characters are written as three-digit octal numbers (with a
|
|
preceding backslash) for each byte in the character (most significant byte
|
|
first).
|
|
Long lines are folded, with the point of folding indicated by displaying
|
|
a backslash followed by a newline.
|
|
The end of each line is marked with a
|
|
.BR $ .
|
|
.IP [2addr]\fBn\fR
|
|
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
|
|
input.
|
|
.IP [2addr]\fBN\fR
|
|
Append the next line of input to the pattern space, using an embedded
|
|
newline character to separate the appended material from the original
|
|
contents.
|
|
Note that the current line number changes.
|
|
.IP [2addr]\fBp\fR
|
|
Write the pattern space to standard output.
|
|
.IP [2addr]\fBP\fR
|
|
Write the pattern space, up to the first newline character to the
|
|
standard output.
|
|
.IP [1addr]\fBq\fR
|
|
Branch to the end of the script and quit without starting a new cycle.
|
|
.IP "[1addr]\fBr\fR file"
|
|
Copy the contents of
|
|
.IR file
|
|
to the standard output immediately before the next attempt to read a
|
|
line of input.
|
|
If
|
|
.IR file
|
|
cannot be read for any reason, it is silently ignored and no error
|
|
condition is set.
|
|
.IP "[2addr]\fBs/\fR regular expression\fB/\fRreplacement\fB/\fRflags"
|
|
Substitute the replacement string for the first instance of the regular
|
|
expression in the pattern space.
|
|
Any character other than backslash or newline can be used instead of
|
|
a slash to delimit the RE and the replacement.
|
|
Within the RE and the replacement, the RE delimiter itself can be used as
|
|
a literal character if it is preceded by a backslash.
|
|
.HP
|
|
An ampersand
|
|
.RB ( & )
|
|
appearing in the replacement is replaced by the string matching the RE.
|
|
The special meaning of
|
|
.BR &
|
|
in this context can be suppressed by preceding it by a backslash.
|
|
The string
|
|
.BR \\\\# ,
|
|
where
|
|
.BR #
|
|
is a digit, is replaced by the text matched
|
|
by the corresponding backreference expression (see
|
|
.BR re_format (7)).
|
|
.HP
|
|
A line can be split by substituting a newline character into it.
|
|
To specify a newline character in the replacement string, precede it with
|
|
a backslash.
|
|
.HP
|
|
The value of
|
|
.IR flags
|
|
in the substitute function is zero or more of the following:
|
|
.RS
|
|
.RP \fB0\fR...\fB9\fR
|
|
Make the substitution only for the N'th occurrence of the regular
|
|
expression in the pattern space.
|
|
.RE
|
|
.RP \fBg\fR
|
|
Make the substitution for all non-overlapping matches of the
|
|
regular expression, not just the first one.
|
|
.RE
|
|
.RP \fBp\fR
|
|
Write the pattern space to standard output if a replacement was made.
|
|
If the replacement string is identical to that which it replaces, it
|
|
is still considered to have been a replacement.
|
|
.RE
|
|
.RP \fBw\fRfile
|
|
Append the pattern space to
|
|
.IR file
|
|
if a replacement was made.
|
|
If the replacement string is identical to that which it replaces, it
|
|
is still considered to have been a replacement.
|
|
.RE
|
|
.IP "[2addr]\fBt\fR [label]"
|
|
Branch to the
|
|
.BR :
|
|
function bearing the label if any substitutions have been made since the
|
|
most recent reading of an input line or execution of a
|
|
.BR t
|
|
function.
|
|
If no label is specified, branch to the end of the script.
|
|
.IP "[2addr]\fBw\fR file"
|
|
Append the pattern space to the
|
|
.IR file .
|
|
.IP [2addr]\fBx\fR
|
|
Swap the contents of the pattern and hold spaces.
|
|
.IP [2addr]\fBy/\fRstring1\fB/\fRstring2\fB/\fR
|
|
Replace all occurrences of characters in
|
|
.IR string1
|
|
in the pattern space with the corresponding characters from
|
|
.IR string2 .
|
|
Any character other than a backslash or newline can be used instead of
|
|
a slash to delimit the strings.
|
|
Within
|
|
.IR string1
|
|
and
|
|
.IR string2 ,
|
|
a backslash followed by any character other than a newline is that literal
|
|
character, and a backslash followed by an ``n'' is replaced by a newline
|
|
character.
|
|
.IP [2addr]\fB!\fRfunction
|
|
.IP [2addr]\fB!\fRfunction-list
|
|
Apply the function or function-list only to the lines that are
|
|
.IR not
|
|
selected by the address(es).
|
|
.IP [0addr]\fB:\fRlabel
|
|
This function does nothing; it bears a label to which the
|
|
.BR b
|
|
and
|
|
.BR t
|
|
commands may branch.
|
|
.IP [1addr]\fB=\fR
|
|
Write the line number to the standard output followed by a newline
|
|
character.
|
|
.IP [0addr]
|
|
Empty lines are ignored.
|
|
.IP [0addr]\fB#\fR
|
|
The
|
|
.BR #
|
|
and the remainder of the line are ignored (treated as a comment), with
|
|
the single exception that if the first two characters in the file are
|
|
.BR #n ,
|
|
the default output is suppressed.
|
|
This is the same as specifying the
|
|
.BR -n
|
|
option on the command line.
|
|
.PP
|
|
The
|
|
.BR sed
|
|
utility exits 0 on success and >0 if an error occurs.
|
|
.SH VERSION
|
|
This manual page documents
|
|
.BR sed
|
|
version 2.0 for GNO/ME.
|
|
.SH SEE ALSO
|
|
.BR awk (1),
|
|
.BR ed (1),
|
|
.BR grep (1),
|
|
.BR regex (3),
|
|
.BR re_format (7)
|
|
.SH ATTRIBUTIONS
|
|
This command was ported from FreeBSD source code
|
|
for distribution with GNO/ME 2.0.6.
|
|
.SH HISTORY
|
|
An implementation of
|
|
.BR sed
|
|
for the Apple IIGS
|
|
was written in 1990 and distributed separately from GNO.
|
|
.SH STANDARDS
|
|
The
|
|
.BR sed
|
|
function is expected to be a superset of the
|
|
POSIX.2
|
|
specification.
|