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