VirtualBox

source: kBuild/vendor/sed/current/doc/sed.x

Last change on this file was 599, checked in by bird, 18 years ago

GNU sed 4.1.5.

File size: 6.6 KB
Line 
1.SH NAME
2sed \- a Stream EDitor
3.SH SYNOPSIS
4.nf
5sed [-V] [--version] [--help] [-n] [--quiet] [--silent]
6 [-l N] [--line-length=N] [-u] [--unbuffered]
7 [-r] [--regexp-extended]
8 [-e script] [--expression=script]
9 [-f script-file] [--file=script-file]
10 [script-if-no-other-script]
11 [file...]
12.fi
13[DESCRIPTION]
14.ds sd \fIsed\fP
15.ds Sd \fISed\fP
16\*(Sd is a stream editor.
17A stream editor is used to perform basic text
18transformations on an input stream
19(a file or input from a pipeline).
20While in some ways similar to an editor which
21permits scripted edits (such as \fIed\fP),
22\*(sd works by making only one pass over the
23input(s), and is consequently more efficient.
24But it is \*(sd's ability to filter text in a pipeline
25which particularly distinguishes it from other types of
26editors.
27
28[COMMAND SYNOPSIS]
29This is just a brief synopsis of \*(sd commands to serve as
30a reminder to those who already know \*(sd;
31other documentation (such as the texinfo document)
32must be consulted for fuller descriptions.
33.SS
34Zero-address ``commands''
35.TP
36.RI :\ label
37Label for
38.B b
39and
40.B t
41commands.
42.TP
43.RI # comment
44The comment extends until the next newline (or the end of a
45.B -e
46script fragment).
47.TP
48}
49The closing bracket of a { } block.
50.SS
51Zero- or One- address commands
52.TP
53=
54Print the current line number.
55.TP
56a \e
57.TP
58.I text
59Append
60.IR text ,
61which has each embedded newline preceded by a backslash.
62.TP
63i \e
64.TP
65.I text
66Insert
67.IR text ,
68which has each embedded newline preceded by a backslash.
69.TP
70q
71Immediately quit the \*(sd script without processing
72any more input,
73except that if auto-print is not disabled
74the current pattern space will be printed.
75.TP
76Q
77Immediately quit the \*(sd script without processing
78any more input.
79.TP
80.RI r\ filename
81Append text read from
82.IR filename .
83.TP
84.RI R\ filename
85Append a line read from
86.IR filename .
87.SS
88Commands which accept address ranges
89.TP
90{
91Begin a block of commands (end with a }).
92.TP
93.RI b\ label
94Branch to
95.IR label ;
96if
97.I label
98is omitted, branch to end of script.
99.TP
100.RI t\ label
101If a s/// has done a successful substitution since the
102last input line was read and since the last t or T
103command, then branch to
104.IR label ;
105if
106.I label
107is omitted, branch to end of script.
108.TP
109.RI T\ label
110If no s/// has done a successful substitution since the
111last input line was read and since the last t or T
112command, then branch to
113.IR label ;
114if
115.I label
116is omitted, branch to end of script.
117.TP
118c \e
119.TP
120.I text
121Replace the selected lines with
122.IR text ,
123which has each embedded newline preceded by a backslash.
124.TP
125d
126Delete pattern space.
127Start next cycle.
128.TP
129D
130Delete up to the first embedded newline in the pattern space.
131Start next cycle, but skip reading from the input
132if there is still data in the pattern space.
133.TP
134h H
135Copy/append pattern space to hold space.
136.TP
137g G
138Copy/append hold space to pattern space.
139.TP
140x
141Exchange the contents of the hold and pattern spaces.
142.TP
143l
144List out the current line in a ``visually unambiguous'' form.
145.TP
146n N
147Read/append the next line of input into the pattern space.
148.TP
149p
150Print the current pattern space.
151.TP
152P
153Print up to the first embedded newline of the current pattern space.
154.TP
155.RI s/ regexp / replacement /
156Attempt to match
157.I regexp
158against the pattern space.
159If successful, replace that portion matched
160with
161.IR replacement .
162The
163.I replacement
164may contain the special character
165.B &
166to refer to that portion of the pattern space which matched,
167and the special escapes \e1 through \e9 to refer to the
168corresponding matching sub-expressions in the
169.IR regexp .
170.TP
171.RI w\ filename
172Write the current pattern space to
173.IR filename .
174.TP
175.RI W\ filename
176Write the first line of the current pattern space to
177.IR filename .
178.TP
179.RI y/ source / dest /
180Transliterate the characters in the pattern space which appear in
181.I source
182to the corresponding character in
183.IR dest .
184.SH
185Addresses
186\*(Sd commands can be given with no addresses, in which
187case the command will be executed for all input lines;
188with one address, in which case the command will only be executed
189for input lines which match that address; or with two
190addresses, in which case the command will be executed
191for all input lines which match the inclusive range of
192lines starting from the first address and continuing to
193the second address.
194Three things to note about address ranges:
195the syntax is
196.IR addr1 , addr2
197(i.e., the addresses are separated by a comma);
198the line which
199.I addr1
200matched will always be accepted,
201even if
202.I addr2
203selects an earlier line;
204and if
205.I addr2
206is a
207.IR regexp ,
208it will not be tested against the line that
209.I addr1
210matched.
211.PP
212After the address (or address-range),
213and before the command, a
214.B !
215may be inserted,
216which specifies that the command shall only be
217executed if the address (or address-range) does
218.B not
219match.
220.PP
221The following address types are supported:
222.TP
223.I number
224Match only the specified line
225.IR number .
226.TP
227.IR first ~ step
228Match every
229.IR step 'th
230line starting with line
231.IR first .
232For example, ``sed -n 1~2p'' will print all the odd-numbered lines in
233the input stream, and the address 2~5 will match every fifth line,
234starting with the second. (This is an extension.)
235.TP
236$
237Match the last line.
238.TP
239.RI / regexp /
240Match lines matching the regular expression
241.IR regexp .
242.TP
243.BI \fR\e\fPc regexp c
244Match lines matching the regular expression
245.IR regexp .
246The
247.B c
248may be any character.
249.PP
250GNU \*(sd also supports some special 2-address forms:
251.TP
252.RI 0, addr2
253Start out in "matched first address" state, until
254.I addr2
255is found.
256This is similar to
257.RI 1, addr2 ,
258except that if
259.I addr2
260matches the very first line of input the
261.RI 0, addr2
262form will be at the end of its range, whereas the
263.RI 1, addr2
264form will still be at the beginning of its range.
265.TP
266.IR addr1 ,+ N
267Will match
268.I addr1
269and the
270.I N
271lines following
272.IR addr1 .
273.TP
274.IR addr1 ,~ N
275Will match
276.I addr1
277and the lines following
278.I addr1
279until the next line whose input line number is a multiple of
280.IR N .
281
282[REGULAR EXPRESSIONS]
283POSIX.2 BREs
284.I should
285be supported, but they aren't completely because of performance
286problems.
287The
288.B \en
289sequence in a regular expression matches the newline character,
290and similarly for
291.BR \ea ,
292.BR \et ,
293and other sequences.
294
295[SEE ALSO]
296.BR awk (1),
297.BR ed (1),
298.BR grep (1),
299.BR tr (1),
300.BR perlre (1),
301sed.info,
302any of various books on \*(sd,
303.na
304the \*(sd FAQ (http://sed.sf.net/grabbag/tutorials/sedfaq.txt),
305http://sed.sf.net/grabbag/.
306
307[BUGS]
308.PP
309E-mail bug reports to
310.BR bonzini@gnu.org .
311Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
312Also, please include the output of ``sed --version'' in the body
313of your report if at all possible.
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette