source: trunk/third/sed/doc/sed.1 @ 17271

Revision 17271, 8.1 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17270, which included commits to RCS files with non-trunk default branches.
Line 
1.\"
2.\" sed.1 - the *roff document processor source for the sed manual
3.\"
4.\" This file is part of GNU sed.
5.\" Copyright (C) 1998 Free Software Foundation, Inc.
6.\"
7.\" This program is free software; you can redistribute it and/or modify
8.\" it under the terms of the GNU General Public License as published by
9.\" the Free Software Foundation; either version 2, or (at your option)
10.\" any later version.
11.\"
12.\" This program is distributed in the hope that it will be useful,
13.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
14.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15.\" GNU General Public License for more details.
16.\"
17.\" You should have received a copy of the GNU General Public License
18.\" along with this program; if not, write to the Free Software
19.\" Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20.TH SED 1 "1998-05-07" "GNU Project"
21.ds sd \fIsed\fP
22.ds Sd \fISed\fP
23.SH NAME
24sed \- a Stream EDitor
25.SH SYNOPSIS
26.nf
27sed [-n] [-V] [--quiet] [--silent] [--version] [--help]
28    [-e script] [--expression=script]
29    [-f script-file] [--file=script-file]
30    [script-if-no-other-script]
31    [file...]
32.fi
33.SH DESCRIPTION
34\*(Sd is a stream editor.
35A stream editor is used to perform basic text
36transformations on an input stream
37(a file or input from a pipeline).
38While in some ways similar to an editor which
39permits scripted edits (such as \fIed\fP),
40\*(sd works by making only one pass over the
41input(s), and is consequently more efficient.
42But it is \*(sd's ability to filter text in a pipeline
43which particularly distinguishes it from other types of
44editors.
45
46.SH OPTIONS
47\*(Sd may be invoked with the following command-line options:
48.TP
49.B -V
50.TP
51.B --version
52Print out the version of sed that is being run and a copyright notice,
53then exit.
54.TP
55.B -h
56.TP
57.B --help
58Print a usage message briefly summarizing these command-line options
59and the bug-reporting address,
60then exit.
61.TP
62.B -n
63.TP
64.B --quiet
65.TP
66.B --silent
67By default, \*(sd will print out the pattern space
68at the end of each cycle through the script.
69These options disable this automatic printing,
70and \*(sd will only produce output when explicitly told to
71via the
72.B p
73command.
74.TP
75.B -e \fIscript\fP
76.TP
77.BI --expression= script
78Add the commands in
79.I script
80to the set of commands to be run while processing the input.
81.TP
82.B -f \fIscript-file\fP
83.TP
84.BI --file= script-file
85Add the commands contained in the file
86.I script-file
87to the set of commands to be run while processing the input.
88.PP
89If no
90.BR -e , -f , --expression ,
91or
92.B --file
93options are given on the command-line,
94then the first non-option argument on the command line is
95taken to be the
96.I script
97to be executed.
98.PP
99If any command-line parameters remain after processing the above,
100these parameters are interpreted as the names of input files to
101be processed.
102A file name of
103.B -
104refers to the standard input stream.
105The standard input will processed if no file names are specified.
106
107.SH
108Command Synopsis
109This is just a brief synopsis of \*(sd commands to serve as
110a reminder to those who already know sed;
111other documentation (such as the texinfo document)
112must be consulted for fuller descriptions.
113.SS
114Zero-address ``commands''
115.TP
116.RI :\  label
117Label for
118.B b
119and
120.B t
121commands.
122.TP
123.RI # comment
124The comment extends until the next newline (or the end of a
125.B -e
126script fragment).
127.TP
128}
129The closing bracket of a { } block.
130.SS
131Zero- or One- address commands
132.TP
133=
134Print the current line number.
135.TP
136a \e
137.TP
138.I text
139Append
140.IR text ,
141which has each embedded newline preceeded by a backslash.
142.TP
143i \e
144.TP
145.I text
146Insert
147.IR text ,
148which has each embedded newline preceeded by a backslash.
149.TP
150q
151Immediately quit the \*(sd script without processing
152any more input,
153except that if auto-print is not diabled
154the current pattern space will be printed.
155.TP
156.RI r\  filename
157Append text read from
158.IR filename .
159.SS
160Commands which accept address ranges
161.TP
162{
163Begin a block of commands (end with a }).
164.TP
165.RI b\  label
166Branch to
167.IR label ;
168if
169.I label
170is omitted, branch to end of script.
171.TP
172.RI t\  label
173If a s/// has done a successful substitution since the
174last input line was read and since the last t command,
175then branch to
176.IR label ;
177if
178.I label
179is omitted, branch to end of script.
180.TP
181c \e
182.TP
183.I text
184Replace the selected lines with
185.IR text ,
186which has each embedded newline preceeded by a backslash.
187.TP
188d
189Delete pattern space.
190Start next cycle.
191.TP
192D
193Delete up to the first embedded newline in the pattern space.
194Start next cycle, but skip reading from the input
195if there is still data in the pattern space.
196.TP
197h H
198Copy/append pattern space to hold space.
199.TP
200g G
201Copy/append hold space to pattern space.
202.TP
203x
204Exchange the contents of the hold and pattern spaces.
205.TP
206l
207List out the current line in a ``visually unambiguous'' form.
208.TP
209n N
210Read/append the next line of input into the pattern space.
211.TP
212p
213Print the current pattern space.
214.TP
215P
216Print up to the first embedded newline of the current pattern space.
217.TP
218.RI s/ regexp / replacement /
219Attempt to match
220.I regexp
221against the pattern space.
222If successful, replace that portion matched
223with
224.IR replacement .
225The
226.I replacement
227may contain the special character
228.B &
229to refer to that portion of the pattern space which matched,
230and the special escapes \e1 through \e9 to refer to the
231corresponding matching sub-expressions in the
232.IR regexp .
233.TP
234w
235.I filename
236Write the current pattern space to
237.IR filename .
238.TP
239.RI y/ source / dest /
240Transliterate the characters in the pattern space which appear in
241.I source
242to the corresponding character in
243.IR dest .
244.SH
245Addresses
246\*(Sd commands can be given with no addresses, in which
247case the command will be executed for all input lines;
248with one address, in which case the command will only be executed
249for input lines which match that address; or with two
250addresses, in which case the command will be executed
251for all input lines which match the inclusive range of
252lines starting from the first address and continuing to
253the second address.
254Three things to note about address ranges:
255the syntax is
256.IR addr1 , addr2
257(i.e., the addresses are separated by a comma);
258the line which
259.I addr1
260matched will always be accepted,
261even if
262.I addr2
263selects an earlier line;
264and if
265.I addr2
266is a
267.IR regexp ,
268it will not be tested against the line that
269.I addr1
270matched.
271.PP
272After the address (or address-range),
273and before the command, a
274.B !
275may be inserted,
276which specifies that the command shall only be
277executed if the address (or address-range) does
278.B not
279match.
280.PP
281The following address types are supported:
282.TP
283.I number
284Match only the specified line
285.IR number .
286.TP
287.IR first ~ step
288Match every
289.IR step 'th
290line starting with line
291.IR first .
292For example, ``sed -n 1~2p'' will print all the odd-numbered lines in
293the input stream, and the address 2~5 will match every fifth line,
294starting with the second.
295(This is a GNU extension.)
296.TP
297$
298Match the last line.
299.TP
300.RI / regexp /
301Match lines matching the regular expression
302.IR regexp .
303.TP
304.BI \fR\e\fPc regexp c
305Match lines matching the regular expression
306.IR regexp .
307The
308.B c
309may be any character.
310.SH
311Regular expressions
312POSIX.2 BREs
313.I should
314be supported, but they aren't completely yet.
315The
316.B \en
317sequence in a regular expression matches the newline character.
318There are also some GNU extensions.
319[XXX FIXME: more needs to be said.
320At the very least, a reference to another document which
321describes what is supported should be given.]
322.SH
323Miscellaneous notes
324This version of sed supports a
325.RB \e <newline>
326sequence in
327all regular expressions, the
328.I replacement
329part of a substitute (s) command, and in the
330.I source
331and
332.I dest
333parts of a transliterate (y) command.
334The \e is stripped, and the newline is kept.
335.SH
336SEE ALSO
337.BR awk (1),
338.BR ed (1),
339.BR expr (1),
340.BR emacs (1),
341.BR perl (1),
342.BR tr (1),
343.BR vi (1),
344.BR regex (5)
345[well, one
346.I ought
347to be written... XXX],
348sed.info,
349any of various books on \*(sd,
350.na
351the \*(sd FAQ (http://www.wollery.demon.co.uk/sedtut10.txt,
352http://www.ptug.org/sed/sedfaq.htm).
353.SH
354BUGS
355.PP
356E-mail bug reports to
357.BR bug-gnu-utils@gnu.org .
358Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
Note: See TracBrowser for help on using the repository browser.