Debian Codegraph @

upstream/fedora-44/man1/sed.1

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