VirtualBox

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

Last change on this file since 3611 was 3611, checked in by bird, 7 months ago

vendor/sed/current: GNU sed 4.9 (sed-4.9.tar.xz sha256:6e226b732e1cd739464ad6862bd1a1aba42d7982922da7a53519631d24975181)

File size: 7.5 KB
Line 
1[NAME]
2sed \- stream editor for filtering and transforming text
3[SYNOPSIS]
4.nf
5sed [-V] [--version] [--help] [-n] [--quiet] [--silent]
6 [-l N] [--line-length=N] [-u] [--unbuffered]
7 [-E] [-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 [\fIexit-code\fR]
71Immediately quit the \*(sd script without processing
72any more input, except that if auto-print is not disabled
73the current pattern space will be printed. The exit code
74argument is a GNU extension.
75.TP
76Q [\fIexit-code\fR]
77Immediately quit the \*(sd script without processing
78any more input. This is a GNU extension.
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 .
87Each invocation of the command reads a line from the file.
88This is a GNU extension.
89.SS
90Commands which accept address ranges
91.TP
92{
93Begin a block of commands (end with a }).
94.TP
95.RI b\ label
96Branch to
97.IR label ;
98if
99.I label
100is omitted, branch to end of script.
101.TP
102c \e
103.TP
104.I text
105Replace the selected lines with
106.IR text ,
107which has each embedded newline preceded by a backslash.
108.TP
109d
110Delete pattern space.
111Start next cycle.
112.TP
113D
114If pattern space contains no newline, start a normal new cycle as if
115the d command was issued. Otherwise, delete text in the pattern
116space up to the first newline, and restart cycle with the resultant
117pattern space, without reading a new line of input.
118.TP
119h H
120Copy/append pattern space to hold space.
121.TP
122g G
123Copy/append hold space to pattern space.
124.TP
125l
126List out the current line in a ``visually unambiguous'' form.
127.TP
128.RI l\ width
129List out the current line in a ``visually unambiguous'' form,
130breaking it at
131.I width
132characters. This is a GNU extension.
133.TP
134n N
135Read/append the next line of input into the pattern space.
136.TP
137p
138Print the current pattern space.
139.TP
140P
141Print up to the first embedded newline of the current pattern space.
142.TP
143.RI s/ regexp / replacement /
144Attempt to match
145.I regexp
146against the pattern space.
147If successful, replace that portion matched
148with
149.IR replacement .
150The
151.I replacement
152may contain the special character
153.B &
154to refer to that portion of the pattern space which matched,
155and the special escapes \e1 through \e9 to refer to the
156corresponding matching sub-expressions in the
157.IR regexp .
158.TP
159.RI t\ label
160If a s/// has done a successful substitution since the
161last input line was read and since the last t or T
162command, then branch to
163.IR label ;
164if
165.I label
166is omitted, branch to end of script.
167.TP
168.RI T\ label
169If no s/// has done a successful substitution since the
170last input line was read and since the last t or T
171command, then branch to
172.IR label ;
173if
174.I label
175is omitted, branch to end of script. This is a GNU
176extension.
177.TP
178.RI w\ filename
179Write the current pattern space to
180.IR filename .
181.TP
182.RI W\ filename
183Write the first line of the current pattern space to
184.IR filename .
185This is a GNU extension.
186.TP
187x
188Exchange the contents of the hold and pattern spaces.
189.TP
190.RI y/ source / dest /
191Transliterate the characters in the pattern space which appear in
192.I source
193to the corresponding character in
194.IR dest .
195.SH
196Addresses
197\*(Sd commands can be given with no addresses, in which
198case the command will be executed for all input lines;
199with one address, in which case the command will only be executed
200for input lines which match that address; or with two
201addresses, in which case the command will be executed
202for all input lines which match the inclusive range of
203lines starting from the first address and continuing to
204the second address.
205Three things to note about address ranges:
206the syntax is
207.IR addr1 , addr2
208(i.e., the addresses are separated by a comma);
209the line which
210.I addr1
211matched will always be accepted,
212even if
213.I addr2
214selects an earlier line;
215and if
216.I addr2
217is a
218.IR regexp ,
219it will not be tested against the line that
220.I addr1
221matched.
222.PP
223After the address (or address-range),
224and before the command, a
225.B !
226may be inserted,
227which specifies that the command shall only be
228executed if the address (or address-range) does
229.B not
230match.
231.PP
232The following address types are supported:
233.TP
234.I number
235Match only the specified line
236.IR number
237(which increments cumulatively across files, unless the
238.B \-s
239option is specified on the command line).
240.TP
241.IR first ~ step
242Match every
243.IR step 'th
244line starting with line
245.IR first .
246For example, ``sed \-n 1~2p'' will print all the odd-numbered lines in
247the input stream, and the address 2~5 will match every fifth line,
248starting with the second.
249.I first
250can be zero; in this case, \*(sd operates as if it were equal to
251.IR step .
252(This is an extension.)
253.TP
254$
255Match the last line.
256.TP
257.RI / regexp /
258Match lines matching the regular expression
259.IR regexp .
260Matching is performed on the current pattern space, which
261can be modified with commands such as ``s///''.
262.TP
263.BI \fR\e\fPc regexp c
264Match lines matching the regular expression
265.IR regexp .
266The
267.B c
268may be any character.
269.PP
270GNU \*(sd also supports some special 2-address forms:
271.TP
272.RI 0, addr2
273Start out in "matched first address" state, until
274.I addr2
275is found.
276This is similar to
277.RI 1, addr2 ,
278except that if
279.I addr2
280matches the very first line of input the
281.RI 0, addr2
282form will be at the end of its range, whereas the
283.RI 1, addr2
284form will still be at the beginning of its range.
285This works only when
286.I addr2
287is a regular expression.
288.TP
289.IR addr1 ,+ N
290Will match
291.I addr1
292and the
293.I N
294lines following
295.IR addr1 .
296.TP
297.IR addr1 ,~ N
298Will match
299.I addr1
300and the lines following
301.I addr1
302until the next line whose input line number is a multiple of
303.IR N .
304
305[REGULAR EXPRESSIONS]
306POSIX.2 BREs
307.I should
308be supported, but they aren't completely because of performance
309problems.
310The
311.B \en
312sequence in a regular expression matches the newline character,
313and similarly for
314.BR \ea ,
315.BR \et ,
316and other sequences.
317The \fI-E\fP option switches to using extended regular expressions instead;
318it has been supported for years by GNU sed, and is now
319included in POSIX.
320
321[SEE ALSO]
322.BR awk (1),
323.BR ed (1),
324.BR grep (1),
325.BR tr (1),
326.BR perlre (1),
327sed.info,
328any of various books on \*(sd,
329.na
330the \*(sd FAQ (http://sed.sf.net/grabbag/tutorials/sedfaq.txt),
331http://sed.sf.net/grabbag/.
332
333[BUGS]
334.PP
335E-mail bug reports to
336.BR [email protected] .
337Also, please include the output of ``sed \-\-version'' in the body
338of your report if at all possible.
Note: See TracBrowser for help on using the repository browser.

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