source: trunk/src/sed/doc/sed.1

Last change on this file was 3613, checked in by bird, 10 months ago

src/sed: Merged in changes between 4.1.5 and 4.9 from the vendor branch. (svn merge /vendor/sed/4.1.5 /vendor/sed/current .)

File size: 10.3 KB
Line 
1.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.48.5.
2.TH SED "1" "November 2022" "GNU sed 4.9" "User Commands"
3.SH NAME
4sed \- stream editor for filtering and transforming text
5.SH SYNOPSIS
6.nf
7sed [-V] [--version] [--help] [-n] [--quiet] [--silent]
8 [-l N] [--line-length=N] [-u] [--unbuffered]
9 [-E] [-r] [--regexp-extended]
10 [-e script] [--expression=script]
11 [-f script-file] [--file=script-file]
12 [script-if-no-other-script]
13 [file...]
14.fi
15.SH DESCRIPTION
16.ds sd \fIsed\fP
17.ds Sd \fISed\fP
18\*(Sd is a stream editor.
19A stream editor is used to perform basic text
20transformations on an input stream
21(a file or input from a pipeline).
22While in some ways similar to an editor which
23permits scripted edits (such as \fIed\fP),
24\*(sd works by making only one pass over the
25input(s), and is consequently more efficient.
26But it is \*(sd's ability to filter text in a pipeline
27which particularly distinguishes it from other types of
28editors.
29.HP
30\fB\-n\fR, \fB\-\-quiet\fR, \fB\-\-silent\fR
31.IP
32suppress automatic printing of pattern space
33.HP
34\fB\-\-debug\fR
35.IP
36annotate program execution
37.HP
38\fB\-e\fR script, \fB\-\-expression\fR=\fI\,script\/\fR
39.IP
40add the script to the commands to be executed
41.HP
42\fB\-f\fR script\-file, \fB\-\-file\fR=\fI\,script\-file\/\fR
43.IP
44add the contents of script\-file to the commands to be executed
45.HP
46\fB\-\-follow\-symlinks\fR
47.IP
48follow symlinks when processing in place
49.HP
50\fB\-i[SUFFIX]\fR, \fB\-\-in\-place\fR[=\fI\,SUFFIX\/\fR]
51.IP
52edit files in place (makes backup if SUFFIX supplied)
53.HP
54\fB\-l\fR N, \fB\-\-line\-length\fR=\fI\,N\/\fR
55.IP
56specify the desired line\-wrap length for the `l' command
57.HP
58\fB\-\-posix\fR
59.IP
60disable all GNU extensions.
61.HP
62\fB\-E\fR, \fB\-r\fR, \fB\-\-regexp\-extended\fR
63.IP
64use extended regular expressions in the script
65(for portability use POSIX \fB\-E\fR).
66.HP
67\fB\-s\fR, \fB\-\-separate\fR
68.IP
69consider files as separate rather than as a single,
70continuous long stream.
71.HP
72\fB\-\-sandbox\fR
73.IP
74operate in sandbox mode (disable e/r/w commands).
75.HP
76\fB\-u\fR, \fB\-\-unbuffered\fR
77.IP
78load minimal amounts of data from the input files and flush
79the output buffers more often
80.HP
81\fB\-z\fR, \fB\-\-null\-data\fR
82.IP
83separate lines by NUL characters
84.TP
85\fB\-\-help\fR
86display this help and exit
87.TP
88\fB\-\-version\fR
89output version information and exit
90.PP
91If no \fB\-e\fR, \fB\-\-expression\fR, \fB\-f\fR, or \fB\-\-file\fR option is given, then the first
92non\-option argument is taken as the sed script to interpret. All
93remaining arguments are names of input files; if no input files are
94specified, then the standard input is read.
95.PP
96GNU sed home page: <https://www.gnu.org/software/sed/>.
97General help using GNU software: <https://www.gnu.org/gethelp/>.
98E\-mail bug reports to: <bug\-sed@gnu.org>.
99.SH "COMMAND SYNOPSIS"
100This is just a brief synopsis of \*(sd commands to serve as
101a reminder to those who already know \*(sd;
102other documentation (such as the texinfo document)
103must be consulted for fuller descriptions.
104.SS
105Zero-address ``commands''
106.TP
107.RI :\ label
108Label for
109.B b
110and
111.B t
112commands.
113.TP
114.RI # comment
115The comment extends until the next newline (or the end of a
116.B \-e
117script fragment).
118.TP
119}
120The closing bracket of a { } block.
121.SS
122Zero- or One- address commands
123.TP
124=
125Print the current line number.
126.TP
127a \e
128.TP
129.I text
130Append
131.IR text ,
132which has each embedded newline preceded by a backslash.
133.TP
134i \e
135.TP
136.I text
137Insert
138.IR text ,
139which has each embedded newline preceded by a backslash.
140.TP
141q [\fIexit-code\fR]
142Immediately quit the \*(sd script without processing
143any more input, except that if auto-print is not disabled
144the current pattern space will be printed. The exit code
145argument is a GNU extension.
146.TP
147Q [\fIexit-code\fR]
148Immediately quit the \*(sd script without processing
149any more input. This is a GNU extension.
150.TP
151.RI r\ filename
152Append text read from
153.IR filename .
154.TP
155.RI R\ filename
156Append a line read from
157.IR filename .
158Each invocation of the command reads a line from the file.
159This is a GNU extension.
160.SS
161Commands which accept address ranges
162.TP
163{
164Begin a block of commands (end with a }).
165.TP
166.RI b\ label
167Branch to
168.IR label ;
169if
170.I label
171is omitted, branch to end of script.
172.TP
173c \e
174.TP
175.I text
176Replace the selected lines with
177.IR text ,
178which has each embedded newline preceded by a backslash.
179.TP
180d
181Delete pattern space.
182Start next cycle.
183.TP
184D
185If pattern space contains no newline, start a normal new cycle as if
186the d command was issued. Otherwise, delete text in the pattern
187space up to the first newline, and restart cycle with the resultant
188pattern space, without reading a new line of input.
189.TP
190h H
191Copy/append pattern space to hold space.
192.TP
193g G
194Copy/append hold space to pattern space.
195.TP
196l
197List out the current line in a ``visually unambiguous'' form.
198.TP
199.RI l\ width
200List out the current line in a ``visually unambiguous'' form,
201breaking it at
202.I width
203characters. This is a GNU extension.
204.TP
205n N
206Read/append the next line of input into the pattern space.
207.TP
208p
209Print the current pattern space.
210.TP
211P
212Print up to the first embedded newline of the current pattern space.
213.TP
214.RI s/ regexp / replacement /
215Attempt to match
216.I regexp
217against the pattern space.
218If successful, replace that portion matched
219with
220.IR replacement .
221The
222.I replacement
223may contain the special character
224.B &
225to refer to that portion of the pattern space which matched,
226and the special escapes \e1 through \e9 to refer to the
227corresponding matching sub-expressions in the
228.IR regexp .
229.TP
230.RI t\ label
231If a s/// has done a successful substitution since the
232last input line was read and since the last t or T
233command, then branch to
234.IR label ;
235if
236.I label
237is omitted, branch to end of script.
238.TP
239.RI T\ label
240If no s/// has done a successful substitution since the
241last input line was read and since the last t or T
242command, then branch to
243.IR label ;
244if
245.I label
246is omitted, branch to end of script. This is a GNU
247extension.
248.TP
249.RI w\ filename
250Write the current pattern space to
251.IR filename .
252.TP
253.RI W\ filename
254Write the first line of the current pattern space to
255.IR filename .
256This is a GNU extension.
257.TP
258x
259Exchange the contents of the hold and pattern spaces.
260.TP
261.RI y/ source / dest /
262Transliterate the characters in the pattern space which appear in
263.I source
264to the corresponding character in
265.IR dest .
266.SH
267Addresses
268\*(Sd commands can be given with no addresses, in which
269case the command will be executed for all input lines;
270with one address, in which case the command will only be executed
271for input lines which match that address; or with two
272addresses, in which case the command will be executed
273for all input lines which match the inclusive range of
274lines starting from the first address and continuing to
275the second address.
276Three things to note about address ranges:
277the syntax is
278.IR addr1 , addr2
279(i.e., the addresses are separated by a comma);
280the line which
281.I addr1
282matched will always be accepted,
283even if
284.I addr2
285selects an earlier line;
286and if
287.I addr2
288is a
289.IR regexp ,
290it will not be tested against the line that
291.I addr1
292matched.
293.PP
294After the address (or address-range),
295and before the command, a
296.B !
297may be inserted,
298which specifies that the command shall only be
299executed if the address (or address-range) does
300.B not
301match.
302.PP
303The following address types are supported:
304.TP
305.I number
306Match only the specified line
307.IR number
308(which increments cumulatively across files, unless the
309.B \-s
310option is specified on the command line).
311.TP
312.IR first ~ step
313Match every
314.IR step 'th
315line starting with line
316.IR first .
317For example, ``sed \-n 1~2p'' will print all the odd-numbered lines in
318the input stream, and the address 2~5 will match every fifth line,
319starting with the second.
320.I first
321can be zero; in this case, \*(sd operates as if it were equal to
322.IR step .
323(This is an extension.)
324.TP
325$
326Match the last line.
327.TP
328.RI / regexp /
329Match lines matching the regular expression
330.IR regexp .
331Matching is performed on the current pattern space, which
332can be modified with commands such as ``s///''.
333.TP
334.BI \fR\e\fPc regexp c
335Match lines matching the regular expression
336.IR regexp .
337The
338.B c
339may be any character.
340.PP
341GNU \*(sd also supports some special 2-address forms:
342.TP
343.RI 0, addr2
344Start out in "matched first address" state, until
345.I addr2
346is found.
347This is similar to
348.RI 1, addr2 ,
349except that if
350.I addr2
351matches the very first line of input the
352.RI 0, addr2
353form will be at the end of its range, whereas the
354.RI 1, addr2
355form will still be at the beginning of its range.
356This works only when
357.I addr2
358is a regular expression.
359.TP
360.IR addr1 ,+ N
361Will match
362.I addr1
363and the
364.I N
365lines following
366.IR addr1 .
367.TP
368.IR addr1 ,~ N
369Will match
370.I addr1
371and the lines following
372.I addr1
373until the next line whose input line number is a multiple of
374.IR N .
375.SH "REGULAR EXPRESSIONS"
376POSIX.2 BREs
377.I should
378be supported, but they aren't completely because of performance
379problems.
380The
381.B \en
382sequence in a regular expression matches the newline character,
383and similarly for
384.BR \ea ,
385.BR \et ,
386and other sequences.
387The \fI-E\fP option switches to using extended regular expressions instead;
388it has been supported for years by GNU sed, and is now
389included in POSIX.
390.SH BUGS
391.PP
392E-mail bug reports to
393.BR bug-sed@gnu.org .
394Also, please include the output of ``sed \-\-version'' in the body
395of your report if at all possible.
396.SH AUTHOR
397Written by Jay Fenlason, Tom Lord, Ken Pizzini,
398Paolo Bonzini, Jim Meyering, and Assaf Gordon.
399.PP
400This sed program was built with SELinux support.
401SELinux is enabled on this system.
402.PP
403GNU sed home page: <https://www.gnu.org/software/sed/>.
404General help using GNU software: <https://www.gnu.org/gethelp/>.
405E\-mail bug reports to: <bug\-sed@gnu.org>.
406.SH COPYRIGHT
407Copyright \(co 2022 Free Software Foundation, Inc.
408License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
409.br
410This is free software: you are free to change and redistribute it.
411There is NO WARRANTY, to the extent permitted by law.
412.SH "SEE ALSO"
413.BR awk (1),
414.BR ed (1),
415.BR grep (1),
416.BR tr (1),
417.BR perlre (1),
418sed.info,
419any of various books on \*(sd,
420.na
421the \*(sd FAQ (http://sed.sf.net/grabbag/tutorials/sedfaq.txt),
422http://sed.sf.net/grabbag/.
423.PP
424The full documentation for
425.B sed
426is maintained as a Texinfo manual. If the
427.B info
428and
429.B sed
430programs are properly installed at your site, the command
431.IP
432.B info sed
433.PP
434should give you access to the complete manual.
Note: See TracBrowser for help on using the repository browser.