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