| 1 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 |
| 2 | .\" |
| 3 | .\" Standard preamble: |
| 4 | .\" ======================================================================== |
| 5 | .de Sh \" Subsection heading |
| 6 | .br |
| 7 | .if t .Sp |
| 8 | .ne 5 |
| 9 | .PP |
| 10 | \fB\\$1\fR |
| 11 | .PP |
| 12 | .. |
| 13 | .de Sp \" Vertical space (when we can't use .PP) |
| 14 | .if t .sp .5v |
| 15 | .if n .sp |
| 16 | .. |
| 17 | .de Vb \" Begin verbatim text |
| 18 | .ft CW |
| 19 | .nf |
| 20 | .ne \\$1 |
| 21 | .. |
| 22 | .de Ve \" End verbatim text |
| 23 | .ft R |
| 24 | .fi |
| 25 | .. |
| 26 | .\" Set up some character translations and predefined strings. \*(-- will |
| 27 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left |
| 28 | .\" double quote, and \*(R" will give a right double quote. | will give a |
| 29 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to |
| 30 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' |
| 31 | .\" expand to `' in nroff, nothing in troff, for use with C<>. |
| 32 | .tr \(*W-|\(bv\*(Tr |
| 33 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' |
| 34 | .ie n \{\ |
| 35 | . ds -- \(*W- |
| 36 | . ds PI pi |
| 37 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch |
| 38 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch |
| 39 | . ds L" "" |
| 40 | . ds R" "" |
| 41 | . ds C` "" |
| 42 | . ds C' "" |
| 43 | 'br\} |
| 44 | .el\{\ |
| 45 | . ds -- \|\(em\| |
| 46 | . ds PI \(*p |
| 47 | . ds L" `` |
| 48 | . ds R" '' |
| 49 | 'br\} |
| 50 | .\" |
| 51 | .\" If the F register is turned on, we'll generate index entries on stderr for |
| 52 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index |
| 53 | .\" entries marked with X<> in POD. Of course, you'll have to process the |
| 54 | .\" output yourself in some meaningful fashion. |
| 55 | .if \nF \{\ |
| 56 | . de IX |
| 57 | . tm Index:\\$1\t\\n%\t"\\$2" |
| 58 | .. |
| 59 | . nr % 0 |
| 60 | . rr F |
| 61 | .\} |
| 62 | .\" |
| 63 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 64 | .\" way too many mistakes in technical documents. |
| 65 | .hy 0 |
| 66 | .if n .na |
| 67 | .\" |
| 68 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). |
| 69 | .\" Fear. Run. Save yourself. No user-serviceable parts. |
| 70 | . \" fudge factors for nroff and troff |
| 71 | .if n \{\ |
| 72 | . ds #H 0 |
| 73 | . ds #V .8m |
| 74 | . ds #F .3m |
| 75 | . ds #[ \f1 |
| 76 | . ds #] \fP |
| 77 | .\} |
| 78 | .if t \{\ |
| 79 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) |
| 80 | . ds #V .6m |
| 81 | . ds #F 0 |
| 82 | . ds #[ \& |
| 83 | . ds #] \& |
| 84 | .\} |
| 85 | . \" simple accents for nroff and troff |
| 86 | .if n \{\ |
| 87 | . ds ' \& |
| 88 | . ds ` \& |
| 89 | . ds ^ \& |
| 90 | . ds , \& |
| 91 | . ds ~ ~ |
| 92 | . ds / |
| 93 | .\} |
| 94 | .if t \{\ |
| 95 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" |
| 96 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' |
| 97 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' |
| 98 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' |
| 99 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' |
| 100 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' |
| 101 | .\} |
| 102 | . \" troff and (daisy-wheel) nroff accents |
| 103 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' |
| 104 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' |
| 105 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] |
| 106 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' |
| 107 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' |
| 108 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] |
| 109 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] |
| 110 | .ds ae a\h'-(\w'a'u*4/10)'e |
| 111 | .ds Ae A\h'-(\w'A'u*4/10)'E |
| 112 | . \" corrections for vroff |
| 113 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' |
| 114 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' |
| 115 | . \" for low resolution devices (crt and lpr) |
| 116 | .if \n(.H>23 .if \n(.V>19 \ |
| 117 | \{\ |
| 118 | . ds : e |
| 119 | . ds 8 ss |
| 120 | . ds o a |
| 121 | . ds d- d\h'-1'\(ga |
| 122 | . ds D- D\h'-1'\(hy |
| 123 | . ds th \o'bp' |
| 124 | . ds Th \o'LP' |
| 125 | . ds ae ae |
| 126 | . ds Ae AE |
| 127 | .\} |
| 128 | .rm #[ #] #H #V #F C |
| 129 | .\" ======================================================================== |
| 130 | .\" |
| 131 | .IX Title "S2P 1" |
| 132 | .TH S2P 1 "2007-06-19" "perl v5.8.8" "Perl Programmers Reference Guide" |
| 133 | .SH "NAME" |
| 134 | psed \- a stream editor |
| 135 | .SH "SYNOPSIS" |
| 136 | .IX Header "SYNOPSIS" |
| 137 | .Vb 2 |
| 138 | \& psed [-an] script [file ...] |
| 139 | \& psed [-an] [-e script] [-f script-file] [file ...] |
| 140 | .Ve |
| 141 | .PP |
| 142 | .Vb 1 |
| 143 | \& s2p [-an] [-e script] [-f script-file] |
| 144 | .Ve |
| 145 | .SH "DESCRIPTION" |
| 146 | .IX Header "DESCRIPTION" |
| 147 | A stream editor reads the input stream consisting of the specified files |
| 148 | (or standard input, if none are given), processes is line by line by |
| 149 | applying a script consisting of edit commands, and writes resulting lines |
| 150 | to standard output. The filename `\f(CW\*(C`\-\*(C'\fR' may be used to read standard input. |
| 151 | .PP |
| 152 | The edit script is composed from arguments of \fB\-e\fR options and |
| 153 | script\-files, in the given order. A single script argument may be specified |
| 154 | as the first parameter. |
| 155 | .PP |
| 156 | If this program is invoked with the name \fIs2p\fR, it will act as a |
| 157 | sed-to-Perl translator. See \*(L"sed Script Translation\*(R". |
| 158 | .PP |
| 159 | \&\fBsed\fR returns an exit code of 0 on success or >0 if an error occurred. |
| 160 | .SH "OPTIONS" |
| 161 | .IX Header "OPTIONS" |
| 162 | .IP "\fB\-a\fR" 4 |
| 163 | .IX Item "-a" |
| 164 | A file specified as argument to the \fBw\fR edit command is by default |
| 165 | opened before input processing starts. Using \fB\-a\fR, opening of such |
| 166 | files is delayed until the first line is actually written to the file. |
| 167 | .IP "\fB\-e\fR \fIscript\fR" 4 |
| 168 | .IX Item "-e script" |
| 169 | The editing commands defined by \fIscript\fR are appended to the script. |
| 170 | Multiple commands must be separated by newlines. |
| 171 | .IP "\fB\-f\fR \fIscript-file\fR" 4 |
| 172 | .IX Item "-f script-file" |
| 173 | Editing commands from the specified \fIscript-file\fR are read and appended |
| 174 | to the script. |
| 175 | .IP "\fB\-n\fR" 4 |
| 176 | .IX Item "-n" |
| 177 | By default, a line is written to standard output after the editing script |
| 178 | has been applied to it. The \fB\-n\fR option suppresses automatic printing. |
| 179 | .SH "COMMANDS" |
| 180 | .IX Header "COMMANDS" |
| 181 | \&\fBsed\fR command syntax is defined as |
| 182 | .PP |
| 183 | \&\& \& \& \&[\fIaddress\fR[\fB,\fR\fIaddress\fR]][\fB!\fR]\fIfunction\fR[\fIargument\fR] |
| 184 | .PP |
| 185 | with whitespace being permitted before or after addresses, and between |
| 186 | the function character and the argument. The \fIaddress\fRes and the |
| 187 | address inverter (\f(CW\*(C`!\*(C'\fR) are used to restrict the application of a |
| 188 | command to the selected line(s) of input. |
| 189 | .PP |
| 190 | Each command must be on a line of its own, except where noted in |
| 191 | the synopses below. |
| 192 | .PP |
| 193 | The edit cycle performed on each input line consist of reading the line |
| 194 | (without its trailing newline character) into the \fIpattern space\fR, |
| 195 | applying the applicable commands of the edit script, writing the final |
| 196 | contents of the pattern space and a newline to the standard output. |
| 197 | A \fIhold space\fR is provided for saving the contents of the |
| 198 | pattern space for later use. |
| 199 | .Sh "Addresses" |
| 200 | .IX Subsection "Addresses" |
| 201 | A sed address is either a line number or a pattern, which may be combined |
| 202 | arbitrarily to construct ranges. Lines are numbered across all input files. |
| 203 | .PP |
| 204 | Any address may be followed by an exclamation mark (`\f(CW\*(C`!\*(C'\fR'), selecting |
| 205 | all lines not matching that address. |
| 206 | .IP "\fInumber\fR" 4 |
| 207 | .IX Item "number" |
| 208 | The line with the given number is selected. |
| 209 | .IP "\fB$\fR" 4 |
| 210 | .IX Item "$" |
| 211 | A dollar sign (\f(CW\*(C`$\*(C'\fR) is the line number of the last line of the input stream. |
| 212 | .IP "\fB/\fR\fIregular expression\fR\fB/\fR" 4 |
| 213 | .IX Item "/regular expression/" |
| 214 | A pattern address is a basic regular expression (see |
| 215 | \&\*(L"Basic Regular Expressions\*(R"), between the delimiting character \f(CW\*(C`/\*(C'\fR. |
| 216 | Any other character except \f(CW\*(C`\e\*(C'\fR or newline may be used to delimit a |
| 217 | pattern address when the initial delimiter is prefixed with a |
| 218 | backslash (`\f(CW\*(C`\e\*(C'\fR'). |
| 219 | .PP |
| 220 | If no address is given, the command selects every line. |
| 221 | .PP |
| 222 | If one address is given, it selects the line (or lines) matching the |
| 223 | address. |
| 224 | .PP |
| 225 | Two addresses select a range that begins whenever the first address |
| 226 | matches, and ends (including that line) when the second address matches. |
| 227 | If the first (second) address is a matching pattern, the second |
| 228 | address is not applied to the very same line to determine the end of |
| 229 | the range. Likewise, if the second address is a matching pattern, the |
| 230 | first address is not applied to the very same line to determine the |
| 231 | begin of another range. If both addresses are line numbers, |
| 232 | and the second line number is less than the first line number, then |
| 233 | only the first line is selected. |
| 234 | .Sh "Functions" |
| 235 | .IX Subsection "Functions" |
| 236 | The maximum permitted number of addresses is indicated with each |
| 237 | function synopsis below. |
| 238 | .PP |
| 239 | The argument \fItext\fR consists of one or more lines following the command. |
| 240 | Embedded newlines in \fItext\fR must be preceded with a backslash. Other |
| 241 | backslashes in \fItext\fR are deleted and the following character is taken |
| 242 | literally. |
| 243 | .IP "[1addr]\fBa\e\fR \fItext\fR" 4 |
| 244 | .IX Item "[1addr]a text" |
| 245 | Write \fItext\fR (which must start on the line following the command) |
| 246 | to standard output immediately before reading the next line |
| 247 | of input, either by executing the \fBN\fR function or by beginning a new cycle. |
| 248 | .IP "[2addr]\fBb\fR [\fIlabel\fR]" 4 |
| 249 | .IX Item "[2addr]b [label]" |
| 250 | Branch to the \fB:\fR function with the specified \fIlabel\fR. If no label |
| 251 | is given, branch to the end of the script. |
| 252 | .IP "[2addr]\fBc\e\fR \fItext\fR" 4 |
| 253 | .IX Item "[2addr]c text" |
| 254 | The line, or range of lines, selected by the address is deleted. |
| 255 | The \fItext\fR (which must start on the line following the command) |
| 256 | is written to standard output. With an address range, this occurs at |
| 257 | the end of the range. |
| 258 | .IP "[2addr]\fBd\fR" 4 |
| 259 | .IX Item "[2addr]d" |
| 260 | Deletes the pattern space and starts the next cycle. |
| 261 | .IP "[2addr]\fBD\fR" 4 |
| 262 | .IX Item "[2addr]D" |
| 263 | Deletes the pattern space through the first embedded newline or to the end. |
| 264 | If the pattern space becomes empty, a new cycle is started, otherwise |
| 265 | execution of the script is restarted. |
| 266 | .IP "[2addr]\fBg\fR" 4 |
| 267 | .IX Item "[2addr]g" |
| 268 | Replace the contents of the pattern space with the hold space. |
| 269 | .IP "[2addr]\fBG\fR" 4 |
| 270 | .IX Item "[2addr]G" |
| 271 | Append a newline and the contents of the hold space to the pattern space. |
| 272 | .IP "[2addr]\fBh\fR" 4 |
| 273 | .IX Item "[2addr]h" |
| 274 | Replace the contents of the hold space with the pattern space. |
| 275 | .IP "[2addr]\fBH\fR" 4 |
| 276 | .IX Item "[2addr]H" |
| 277 | Append a newline and the contents of the pattern space to the hold space. |
| 278 | .IP "[1addr]\fBi\e\fR \fItext\fR" 4 |
| 279 | .IX Item "[1addr]i text" |
| 280 | Write the \fItext\fR (which must start on the line following the command) |
| 281 | to standard output. |
| 282 | .IP "[2addr]\fBl\fR" 4 |
| 283 | .IX Item "[2addr]l" |
| 284 | Print the contents of the pattern space: non-printable characters are |
| 285 | shown in C\-style escaped form; long lines are split and have a trailing |
| 286 | `\f(CW\*(C`\e\*(C'\fR' at the point of the split; the true end of a line is marked with |
| 287 | a `\f(CW\*(C`$\*(C'\fR'. Escapes are: `\ea', `\et', `\en', `\ef', `\er', `\ee' for |
| 288 | \&\s-1BEL\s0, \s-1HT\s0, \s-1LF\s0, \s-1FF\s0, \s-1CR\s0, \s-1ESC\s0, respectively, and `\e' followed by a three-digit |
| 289 | octal number for all other non-printable characters. |
| 290 | .IP "[2addr]\fBn\fR" 4 |
| 291 | .IX Item "[2addr]n" |
| 292 | If automatic printing is enabled, write the pattern space to the standard |
| 293 | output. Replace the pattern space with the next line of input. If |
| 294 | there is no more input, processing is terminated. |
| 295 | .IP "[2addr]\fBN\fR" 4 |
| 296 | .IX Item "[2addr]N" |
| 297 | Append a newline and the next line of input to the pattern space. If |
| 298 | there is no more input, processing is terminated. |
| 299 | .IP "[2addr]\fBp\fR" 4 |
| 300 | .IX Item "[2addr]p" |
| 301 | Print the pattern space to the standard output. (Use the \fB\-n\fR option |
| 302 | to suppress automatic printing at the end of a cycle if you want to |
| 303 | avoid double printing of lines.) |
| 304 | .IP "[2addr]\fBP\fR" 4 |
| 305 | .IX Item "[2addr]P" |
| 306 | Prints the pattern space through the first embedded newline or to the end. |
| 307 | .IP "[1addr]\fBq\fR" 4 |
| 308 | .IX Item "[1addr]q" |
| 309 | Branch to the end of the script and quit without starting a new cycle. |
| 310 | .IP "[1addr]\fBr\fR \fIfile\fR" 4 |
| 311 | .IX Item "[1addr]r file" |
| 312 | Copy the contents of the \fIfile\fR to standard output immediately before |
| 313 | the next attempt to read a line of input. Any error encountered while |
| 314 | reading \fIfile\fR is silently ignored. |
| 315 | .IP "[2addr]\fBs/\fR\fIregular expression\fR\fB/\fR\fIreplacement\fR\fB/\fR\fIflags\fR" 4 |
| 316 | .IX Item "[2addr]s/regular expression/replacement/flags" |
| 317 | Substitute the \fIreplacement\fR string for the first substring in |
| 318 | the pattern space that matches the \fIregular expression\fR. |
| 319 | Any character other than backslash or newline can be used instead of a |
| 320 | slash to delimit the regular expression and the replacement. |
| 321 | To use the delimiter as a literal character within the regular expression |
| 322 | and the replacement, precede the character by a backslash (`\f(CW\*(C`\e\*(C'\fR'). |
| 323 | .Sp |
| 324 | Literal newlines may be embedded in the replacement string by |
| 325 | preceding a newline with a backslash. |
| 326 | .Sp |
| 327 | Within the replacement, an ampersand (`\f(CW\*(C`&\*(C'\fR') is replaced by the string |
| 328 | matching the regular expression. The strings `\f(CW\*(C`\e1\*(C'\fR' through `\f(CW\*(C`\e9\*(C'\fR' are |
| 329 | replaced by the corresponding subpattern (see \*(L"Basic Regular Expressions\*(R"). |
| 330 | To get a literal `\f(CW\*(C`&\*(C'\fR' or `\f(CW\*(C`\e\*(C'\fR' in the replacement text, precede it |
| 331 | by a backslash. |
| 332 | .Sp |
| 333 | The following \fIflags\fR modify the behaviour of the \fBs\fR command: |
| 334 | .RS 4 |
| 335 | .IP "\fBg\fR" 8 |
| 336 | .IX Item "g" |
| 337 | The replacement is performed for all matching, non-overlapping substrings |
| 338 | of the pattern space. |
| 339 | .IP "\fB1\fR..\fB9\fR" 8 |
| 340 | .IX Item "1..9" |
| 341 | Replace only the n\-th matching substring of the pattern space. |
| 342 | .IP "\fBp\fR" 8 |
| 343 | .IX Item "p" |
| 344 | If the substitution was made, print the new value of the pattern space. |
| 345 | .IP "\fBw\fR \fIfile\fR" 8 |
| 346 | .IX Item "w file" |
| 347 | If the substitution was made, write the new value of the pattern space |
| 348 | to the specified file. |
| 349 | .RE |
| 350 | .RS 4 |
| 351 | .RE |
| 352 | .IP "[2addr]\fBt\fR [\fIlabel\fR]" 4 |
| 353 | .IX Item "[2addr]t [label]" |
| 354 | Branch to the \fB:\fR function with the specified \fIlabel\fR if any \fBs\fR |
| 355 | substitutions have been made since the most recent reading of an input line |
| 356 | or execution of a \fBt\fR function. If no label is given, branch to the end of |
| 357 | the script. |
| 358 | .IP "[2addr]\fBw\fR \fIfile\fR" 4 |
| 359 | .IX Item "[2addr]w file" |
| 360 | The contents of the pattern space are written to the \fIfile\fR. |
| 361 | .IP "[2addr]\fBx\fR" 4 |
| 362 | .IX Item "[2addr]x" |
| 363 | Swap the contents of the pattern space and the hold space. |
| 364 | .IP "[1addr]\fB=\fR" 4 |
| 365 | .IX Item "[1addr]=" |
| 366 | Prints the current line number on the standard output. |
| 367 | .IP "[0addr]\fB:\fR [\fIlabel\fR]" 4 |
| 368 | .IX Item "[0addr]: [label]" |
| 369 | The command specifies the position of the \fIlabel\fR. It has no other effect. |
| 370 | .IP "[2addr]\fB{\fR [\fIcommand\fR]" 4 |
| 371 | .IX Item "[2addr]{ [command]" |
| 372 | .PD 0 |
| 373 | .IP "[0addr]\fB}\fR" 4 |
| 374 | .IX Item "[0addr]}" |
| 375 | .PD |
| 376 | These two commands begin and end a command list. The first command may |
| 377 | be given on the same line as the opening \fB{\fR command. The commands |
| 378 | within the list are jointly selected by the address(es) given on the |
| 379 | \&\fB{\fR command (but may still have individual addresses). |
| 380 | .IP "[0addr]\fB#\fR [\fIcomment\fR]" 4 |
| 381 | .IX Item "[0addr]# [comment]" |
| 382 | The entire line is ignored (treated as a comment). If, however, the first |
| 383 | two characters in the script are `\f(CW\*(C`#n\*(C'\fR', automatic printing of output is |
| 384 | suppressed, as if the \fB\-n\fR option were given on the command line. |
| 385 | .SH "BASIC REGULAR EXPRESSIONS" |
| 386 | .IX Header "BASIC REGULAR EXPRESSIONS" |
| 387 | A \fIBasic Regular Expression\fR (\s-1BRE\s0), as defined in \s-1POSIX\s0 1003.2, consists |
| 388 | of \fIatoms\fR, for matching parts of a string, and \fIbounds\fR, specifying |
| 389 | repetitions of a preceding atom. |
| 390 | .Sh "Atoms" |
| 391 | .IX Subsection "Atoms" |
| 392 | The possible atoms of a \s-1BRE\s0 are: \fB.\fR, matching any single character; |
| 393 | \&\fB^\fR and \fB$\fR, matching the null string at the beginning or end |
| 394 | of a string, respectively; a \fIbracket expressions\fR, enclosed |
| 395 | in \fB[\fR and \fB]\fR (see below); and any single character with no |
| 396 | other significance (matching that character). A \fB\e\fR before one |
| 397 | of: \fB.\fR, \fB^\fR, \fB$\fR, \fB[\fR, \fB*\fR, \fB\e\fR, matching the character |
| 398 | after the backslash. A sequence of atoms enclosed in \fB\e(\fR and \fB\e)\fR |
| 399 | becomes an atom and establishes the target for a \fIbackreference\fR, |
| 400 | consisting of the substring that actually matches the enclosed atoms. |
| 401 | Finally, \fB\e\fR followed by one of the digits \fB0\fR through \fB9\fR is a |
| 402 | backreference. |
| 403 | .PP |
| 404 | A \fB^\fR that is not first, or a \fB$\fR that is not last does not have |
| 405 | a special significance and need not be preceded by a backslash to |
| 406 | become literal. The same is true for a \fB]\fR, that does not terminate |
| 407 | a bracket expression. |
| 408 | .PP |
| 409 | An unescaped backslash cannot be last in a \s-1BRE\s0. |
| 410 | .Sh "Bounds" |
| 411 | .IX Subsection "Bounds" |
| 412 | The \s-1BRE\s0 bounds are: \fB*\fR, specifying 0 or more matches of the preceding |
| 413 | atom; \fB\e{\fR\fIcount\fR\fB\e}\fR, specifying that many repetitions; |
| 414 | \&\fB\e{\fR\fIminimum\fR\fB,\e}\fR, giving a lower limit; and |
| 415 | \&\fB\e{\fR\fIminimum\fR\fB,\fR\fImaximum\fR\fB\e}\fR finally defines a lower and upper |
| 416 | bound. |
| 417 | .PP |
| 418 | A bound appearing as the first item in a \s-1BRE\s0 is taken literally. |
| 419 | .Sh "Bracket Expressions" |
| 420 | .IX Subsection "Bracket Expressions" |
| 421 | A \fIbracket expression\fR is a list of characters, character ranges |
| 422 | and character classes enclosed in \fB[\fR and \fB]\fR and matches any |
| 423 | single character from the represented set of characters. |
| 424 | .PP |
| 425 | A character range is written as two characters separated by \fB\-\fR and |
| 426 | represents all characters (according to the character collating sequence) |
| 427 | that are not less than the first and not greater than the second. |
| 428 | (Ranges are very collating\-sequence\-dependent, and portable programs |
| 429 | should avoid relying on them.) |
| 430 | .PP |
| 431 | A character class is one of the class names |
| 432 | .PP |
| 433 | .Vb 4 |
| 434 | \& alnum digit punct |
| 435 | \& alpha graph space |
| 436 | \& blank lower upper |
| 437 | \& cntrl print xdigit |
| 438 | .Ve |
| 439 | .PP |
| 440 | enclosed in \fB[:\fR and \fB:]\fR and represents the set of characters |
| 441 | as defined in \fIctype\fR\|(3). |
| 442 | .PP |
| 443 | If the first character after \fB[\fR is \fB^\fR, the sense of matching is |
| 444 | inverted. |
| 445 | .PP |
| 446 | To include a literal `\f(CW\*(C`^\*(C'\fR', place it anywhere else but first. To |
| 447 | include a literal '\f(CW\*(C`]\*(C'\fR' place it first or immediately after an |
| 448 | initial \fB^\fR. To include a literal `\f(CW\*(C`\-\*(C'\fR' make it the first (or |
| 449 | second after \fB^\fR) or last character, or the second endpoint of |
| 450 | a range. |
| 451 | .PP |
| 452 | The special bracket expression constructs \f(CW\*(C`[[:<:]]\*(C'\fR and \f(CW\*(C`[[:>:]]\*(C'\fR |
| 453 | match the null string at the beginning and end of a word respectively. |
| 454 | (Note that neither is identical to Perl's `\eb' atom.) |
| 455 | .Sh "Additional Atoms" |
| 456 | .IX Subsection "Additional Atoms" |
| 457 | Since some sed implementations provide additional regular expression |
| 458 | atoms (not defined in \s-1POSIX\s0 1003.2), \fBpsed\fR is capable of translating |
| 459 | the following backslash escapes: |
| 460 | .ie n .IP "\fB\e<\fR This is the same as ""[[:>:]]""." 4 |
| 461 | .el .IP "\fB\e<\fR This is the same as \f(CW[[:>:]]\fR." 4 |
| 462 | .IX Item "< This is the same as [[:>:]]." |
| 463 | .PD 0 |
| 464 | .ie n .IP "\fB\e>\fR This is the same as ""[[:<:]]""." 4 |
| 465 | .el .IP "\fB\e>\fR This is the same as \f(CW[[:<:]]\fR." 4 |
| 466 | .IX Item "> This is the same as [[:<:]]." |
| 467 | .ie n .IP "\fB\ew\fR This is an abbreviation for ""[[:alnum:]_]""." 4 |
| 468 | .el .IP "\fB\ew\fR This is an abbreviation for \f(CW[[:alnum:]_]\fR." 4 |
| 469 | .IX Item "w This is an abbreviation for [[:alnum:]_]." |
| 470 | .ie n .IP "\fB\eW\fR This is an abbreviation for ""[^[:alnum:]_]""." 4 |
| 471 | .el .IP "\fB\eW\fR This is an abbreviation for \f(CW[^[:alnum:]_]\fR." 4 |
| 472 | .IX Item "W This is an abbreviation for [^[:alnum:]_]." |
| 473 | .IP "\fB\ey\fR Match the empty string at a word boundary." 4 |
| 474 | .IX Item "y Match the empty string at a word boundary." |
| 475 | .IP "\fB\eB\fR Match the empty string between any two either word or non-word characters." 4 |
| 476 | .IX Item "B Match the empty string between any two either word or non-word characters." |
| 477 | .PD |
| 478 | .PP |
| 479 | To enable this feature, the environment variable \s-1PSEDEXTBRE\s0 must be set |
| 480 | to a string containing the requested characters, e.g.: |
| 481 | \&\f(CW\*(C`PSEDEXTBRE='<>wW'\*(C'\fR. |
| 482 | .SH "ENVIRONMENT" |
| 483 | .IX Header "ENVIRONMENT" |
| 484 | The environment variable \f(CW\*(C`PSEDEXTBRE\*(C'\fR may be set to extend BREs. |
| 485 | See \*(L"Additional Atoms\*(R". |
| 486 | .SH "DIAGNOSTICS" |
| 487 | .IX Header "DIAGNOSTICS" |
| 488 | .IP "ambiguous translation for character `%s' in `y' command" 4 |
| 489 | .IX Item "ambiguous translation for character `%s' in `y' command" |
| 490 | The indicated character appears twice, with different translations. |
| 491 | .IP "`[' cannot be last in pattern" 4 |
| 492 | .IX Item "`[' cannot be last in pattern" |
| 493 | A `[' in a \s-1BRE\s0 indicates the beginning of a \fIbracket expression\fR. |
| 494 | .IP "`\e' cannot be last in pattern" 4 |
| 495 | .IX Item "`' cannot be last in pattern" |
| 496 | A `\e' in a \s-1BRE\s0 is used to make the subsequent character literal. |
| 497 | .IP "`\e' cannot be last in substitution" 4 |
| 498 | .IX Item "`' cannot be last in substitution" |
| 499 | A `\e' in a subsitution string is used to make the subsequent character literal. |
| 500 | .IP "conflicting flags `%s'" 4 |
| 501 | .IX Item "conflicting flags `%s'" |
| 502 | In an \fBs\fR command, either the `g' flag and an n\-th occurrence flag, or |
| 503 | multiple n\-th occurrence flags are specified. Note that only the digits |
| 504 | `1' through `9' are permitted. |
| 505 | .ie n .IP "duplicate label %s\fR (first defined at \f(CW%s)" 4 |
| 506 | .el .IP "duplicate label \f(CW%s\fR (first defined at \f(CW%s\fR)" 4 |
| 507 | .IX Item "duplicate label %s (first defined at %s)" |
| 508 | .PD 0 |
| 509 | .IP "excess address(es)" 4 |
| 510 | .IX Item "excess address(es)" |
| 511 | .PD |
| 512 | The command has more than the permitted number of addresses. |
| 513 | .IP "extra characters after command (%s)" 4 |
| 514 | .IX Item "extra characters after command (%s)" |
| 515 | .PD 0 |
| 516 | .IP "illegal option `%s'" 4 |
| 517 | .IX Item "illegal option `%s'" |
| 518 | .IP "improper delimiter in s command" 4 |
| 519 | .IX Item "improper delimiter in s command" |
| 520 | .PD |
| 521 | The \s-1BRE\s0 and substitution may not be delimited with `\e' or newline. |
| 522 | .IP "invalid address after `,'" 4 |
| 523 | .IX Item "invalid address after `,'" |
| 524 | .PD 0 |
| 525 | .IP "invalid backreference (%s)" 4 |
| 526 | .IX Item "invalid backreference (%s)" |
| 527 | .PD |
| 528 | The specified backreference number exceeds the number of backreferences |
| 529 | in the \s-1BRE\s0. |
| 530 | .IP "invalid repeat clause `\e{%s\e}'" 4 |
| 531 | .IX Item "invalid repeat clause `{%s}'" |
| 532 | The repeat clause does not contain a valid integer value, or pair of |
| 533 | values. |
| 534 | .IP "malformed regex, 1st address" 4 |
| 535 | .IX Item "malformed regex, 1st address" |
| 536 | .PD 0 |
| 537 | .IP "malformed regex, 2nd address" 4 |
| 538 | .IX Item "malformed regex, 2nd address" |
| 539 | .IP "malformed regular expression" 4 |
| 540 | .IX Item "malformed regular expression" |
| 541 | .IP "malformed substitution expression" 4 |
| 542 | .IX Item "malformed substitution expression" |
| 543 | .IP "malformed `y' command argument" 4 |
| 544 | .IX Item "malformed `y' command argument" |
| 545 | .PD |
| 546 | The first or second string of a \fBy\fR command is syntactically incorrect. |
| 547 | .IP "maximum less than minimum in `\e{%s\e}'" 4 |
| 548 | .IX Item "maximum less than minimum in `{%s}'" |
| 549 | .PD 0 |
| 550 | .IP "no script command given" 4 |
| 551 | .IX Item "no script command given" |
| 552 | .PD |
| 553 | There must be at least one \fB\-e\fR or one \fB\-f\fR option specifying a |
| 554 | script or script file. |
| 555 | .IP "`\e' not valid as delimiter in `y' command" 4 |
| 556 | .IX Item "`' not valid as delimiter in `y' command" |
| 557 | .PD 0 |
| 558 | .IP "option \-e requires an argument" 4 |
| 559 | .IX Item "option -e requires an argument" |
| 560 | .IP "option \-f requires an argument" 4 |
| 561 | .IX Item "option -f requires an argument" |
| 562 | .IP "`s' command requires argument" 4 |
| 563 | .IX Item "`s' command requires argument" |
| 564 | .IP "start of unterminated `{'" 4 |
| 565 | .IX Item "start of unterminated `{'" |
| 566 | .IP "string lengths in `y' command differ" 4 |
| 567 | .IX Item "string lengths in `y' command differ" |
| 568 | .PD |
| 569 | The translation table strings in a \fBy\fR commanf must have equal lengths. |
| 570 | .IP "undefined label `%s'" 4 |
| 571 | .IX Item "undefined label `%s'" |
| 572 | .PD 0 |
| 573 | .IP "unexpected `}'" 4 |
| 574 | .IX Item "unexpected `}'" |
| 575 | .PD |
| 576 | A \fB}\fR command without a preceding \fB{\fR command was encountered. |
| 577 | .IP "unexpected end of script" 4 |
| 578 | .IX Item "unexpected end of script" |
| 579 | The end of the script was reached although a text line after a |
| 580 | \&\fBa\fR, \fBc\fR or \fBi\fR command indicated another line. |
| 581 | .IP "unknown command `%s'" 4 |
| 582 | .IX Item "unknown command `%s'" |
| 583 | .PD 0 |
| 584 | .IP "unterminated `['" 4 |
| 585 | .IX Item "unterminated `['" |
| 586 | .PD |
| 587 | A \s-1BRE\s0 contains an unterminated bracket expression. |
| 588 | .IP "unterminated `\e('" 4 |
| 589 | .IX Item "unterminated `('" |
| 590 | A \s-1BRE\s0 contains an unterminated backreference. |
| 591 | .IP "`\e{' without closing `\e}'" 4 |
| 592 | .IX Item "`{' without closing `}'" |
| 593 | A \s-1BRE\s0 contains an unterminated bounds specification. |
| 594 | .IP "`\e)' without preceding `\e('" 4 |
| 595 | .IX Item "`)' without preceding `('" |
| 596 | .PD 0 |
| 597 | .IP "`y' command requires argument" 4 |
| 598 | .IX Item "`y' command requires argument" |
| 599 | .PD |
| 600 | .SH "EXAMPLE" |
| 601 | .IX Header "EXAMPLE" |
| 602 | The basic material for the preceding section was generated by running |
| 603 | the sed script |
| 604 | .PP |
| 605 | .Vb 10 |
| 606 | \& #no autoprint |
| 607 | \& s/^.*Warn( *"\e([^"]*\e)".*$/\e1/ |
| 608 | \& t process |
| 609 | \& b |
| 610 | \& :process |
| 611 | \& s/$!/%s/g |
| 612 | \& s/$[_[:alnum:]]\e{1,\e}/%s/g |
| 613 | \& s/\e\e\e\e/\e\e/g |
| 614 | \& s/^/=item / |
| 615 | \& p |
| 616 | .Ve |
| 617 | .PP |
| 618 | on the program's own text, and piping the output into \f(CW\*(C`sort \-u\*(C'\fR. |
| 619 | .SH "SED SCRIPT TRANSLATION" |
| 620 | .IX Header "SED SCRIPT TRANSLATION" |
| 621 | If this program is invoked with the name \fIs2p\fR it will act as a |
| 622 | sed-to-Perl translator. After option processing (all other |
| 623 | arguments are ignored), a Perl program is printed on standard |
| 624 | output, which will process the input stream (as read from all |
| 625 | arguments) in the way defined by the sed script and the option setting |
| 626 | used for the translation. |
| 627 | .SH "SEE ALSO" |
| 628 | .IX Header "SEE ALSO" |
| 629 | \&\fIperl\fR\|(1), \fIre_format\fR\|(7) |
| 630 | .SH "BUGS" |
| 631 | .IX Header "BUGS" |
| 632 | The \fBl\fR command will show escape characters (\s-1ESC\s0) as `\f(CW\*(C`\ee\*(C'\fR', but |
| 633 | a vertical tab (\s-1VT\s0) in octal. |
| 634 | .PP |
| 635 | Trailing spaces are truncated from labels in \fB:\fR, \fBt\fR and \fBb\fR commands. |
| 636 | .PP |
| 637 | The meaning of an empty regular expression (`\f(CW\*(C`//\*(C'\fR'), as defined by \fBsed\fR, |
| 638 | is \*(L"the last pattern used, at run time\*(R". This deviates from the Perl |
| 639 | interpretation, which will re-use the \*(L"last last successfully executed |
| 640 | regular expression\*(R". Since keeping track of pattern usage would create |
| 641 | terribly cluttered code, and differences would only appear in obscure |
| 642 | context (where other \fBsed\fR implementations appear to deviate, too), |
| 643 | the Perl semantics was adopted. Note that common usage of this feature, |
| 644 | such as in \f(CW\*(C`/abc/s//xyz/\*(C'\fR, will work as expected. |
| 645 | .PP |
| 646 | Collating elements (of bracket expressions in BREs) are not implemented. |
| 647 | .SH "STANDARDS" |
| 648 | .IX Header "STANDARDS" |
| 649 | This \fBsed\fR implementation conforms to the \s-1IEEE\s0 Std1003.2\-1992 (\*(L"\s-1POSIX\s0.2\*(R") |
| 650 | definition of \fBsed\fR, and is compatible with the \fIOpenBSD\fR |
| 651 | implementation, except where otherwise noted (see \*(L"\s-1BUGS\s0\*(R"). |
| 652 | .SH "AUTHOR" |
| 653 | .IX Header "AUTHOR" |
| 654 | This Perl implementation of \fIsed\fR was written by Wolfgang Laun, |
| 655 | \&\fIWolfgang.Laun@alcatel.at\fR. |
| 656 | .SH "COPYRIGHT and LICENSE" |
| 657 | .IX Header "COPYRIGHT and LICENSE" |
| 658 | This program is free and open software. You may use, modify, |
| 659 | distribute, and sell this program (and any modified variants) in any |
| 660 | way you wish, provided you do not restrict others from doing the same. |