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