2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
6 ($startperl = <<'/../') =~ s/\s*\z//;
9 ($perlpath = <<'/../') =~ s/\s*\z//;
13 $0 =~ s/^.*?(\w+)[\.\w]*$/$1/;
15 # (p)sed - a stream editor
16 # History: Aug 12 2000: Original version.
17 # Mar 25 2002: Rearrange generated Perl program.
18 # Jul 23 2007: Fix bug in regex stripping (M.Thorland)
26 psed - a stream editor
30 psed [-an] script [file ...]
31 psed [-an] [-e script] [-f script-file] [file ...]
33 s2p [-an] [-e script] [-f script-file]
37 A stream editor reads the input stream consisting of the specified files
38 (or standard input, if none are given), processes is line by line by
39 applying a script consisting of edit commands, and writes resulting lines
40 to standard output. The filename `C<->' may be used to read standard input.
42 The edit script is composed from arguments of B<-e> options and
43 script-files, in the given order. A single script argument may be specified
44 as the first parameter.
46 If this program is invoked with the name F<s2p>, it will act as a
47 sed-to-Perl translator. See L<"sed Script Translation">.
49 B<sed> returns an exit code of 0 on success or >0 if an error occurred.
57 A file specified as argument to the B<w> edit command is by default
58 opened before input processing starts. Using B<-a>, opening of such
59 files is delayed until the first line is actually written to the file.
63 The editing commands defined by I<script> are appended to the script.
64 Multiple commands must be separated by newlines.
66 =item B<-f> I<script-file>
68 Editing commands from the specified I<script-file> are read and appended
73 By default, a line is written to standard output after the editing script
74 has been applied to it. The B<-n> option suppresses automatic printing.
80 B<sed> command syntax is defined as
82 Z<> Z<> Z<> Z<>[I<address>[B<,>I<address>]][B<!>]I<function>[I<argument>]
84 with whitespace being permitted before or after addresses, and between
85 the function character and the argument. The I<address>es and the
86 address inverter (C<!>) are used to restrict the application of a
87 command to the selected line(s) of input.
89 Each command must be on a line of its own, except where noted in
92 The edit cycle performed on each input line consist of reading the line
93 (without its trailing newline character) into the I<pattern space>,
94 applying the applicable commands of the edit script, writing the final
95 contents of the pattern space and a newline to the standard output.
96 A I<hold space> is provided for saving the contents of the
97 pattern space for later use.
101 A sed address is either a line number or a pattern, which may be combined
102 arbitrarily to construct ranges. Lines are numbered across all input files.
104 Any address may be followed by an exclamation mark (`C<!>'), selecting
105 all lines not matching that address.
111 The line with the given number is selected.
115 A dollar sign (C<$>) is the line number of the last line of the input stream.
117 =item B</>I<regular expression>B</>
119 A pattern address is a basic regular expression (see
120 L<"Basic Regular Expressions">), between the delimiting character C</>.
121 Any other character except C<\> or newline may be used to delimit a
122 pattern address when the initial delimiter is prefixed with a
127 If no address is given, the command selects every line.
129 If one address is given, it selects the line (or lines) matching the
132 Two addresses select a range that begins whenever the first address
133 matches, and ends (including that line) when the second address matches.
134 If the first (second) address is a matching pattern, the second
135 address is not applied to the very same line to determine the end of
136 the range. Likewise, if the second address is a matching pattern, the
137 first address is not applied to the very same line to determine the
138 begin of another range. If both addresses are line numbers,
139 and the second line number is less than the first line number, then
140 only the first line is selected.
145 The maximum permitted number of addresses is indicated with each
146 function synopsis below.
148 The argument I<text> consists of one or more lines following the command.
149 Embedded newlines in I<text> must be preceded with a backslash. Other
150 backslashes in I<text> are deleted and the following character is taken
159 #--------------------------------------------------------------------------
160 $ComTab{'a'}=[ 1, 'txt', \&Emit, '{ push( @Q, <<'."'TheEnd' ) }\n" ]; #ok
162 =item [1addr]B<a\> I<text>
164 Write I<text> (which must start on the line following the command)
165 to standard output immediately before reading the next line
166 of input, either by executing the B<N> function or by beginning a new cycle.
170 #--------------------------------------------------------------------------
171 $ComTab{'b'}=[ 2, 'str', \&Branch, '{ goto XXX; }' ]; #ok
173 =item [2addr]B<b> [I<label>]
175 Branch to the B<:> function with the specified I<label>. If no label
176 is given, branch to the end of the script.
180 #--------------------------------------------------------------------------
181 $ComTab{'c'}=[ 2, 'txt', \&Change, <<'-X-' ]; #ok
182 { print <<'TheEnd'; } $doPrint = 0; goto EOS;
184 ### continue OK => next CYCLE;
186 =item [2addr]B<c\> I<text>
188 The line, or range of lines, selected by the address is deleted.
189 The I<text> (which must start on the line following the command)
190 is written to standard output. With an address range, this occurs at
191 the end of the range.
195 #--------------------------------------------------------------------------
196 $ComTab{'d'}=[ 2, '', \&Emit, <<'-X-' ]; #ok
201 ### continue OK => next CYCLE;
205 Deletes the pattern space and starts the next cycle.
209 #--------------------------------------------------------------------------
210 $ComTab{'D'}=[ 2, '', \&Emit, <<'-X-' ]; #ok
212 if(length($_)){ goto BOS } else { goto EOS }
215 ### continue OK => next CYCLE;
219 Deletes the pattern space through the first embedded newline or to the end.
220 If the pattern space becomes empty, a new cycle is started, otherwise
221 execution of the script is restarted.
225 #--------------------------------------------------------------------------
226 $ComTab{'g'}=[ 2, '', \&Emit, '{ $_ = $Hold };' ]; #ok
230 Replace the contents of the pattern space with the hold space.
234 #--------------------------------------------------------------------------
235 $ComTab{'G'}=[ 2, '', \&Emit, '{ $_ .= "\n"; $_ .= $Hold };' ]; #ok
239 Append a newline and the contents of the hold space to the pattern space.
243 #--------------------------------------------------------------------------
244 $ComTab{'h'}=[ 2, '', \&Emit, '{ $Hold = $_ }' ]; #ok
248 Replace the contents of the hold space with the pattern space.
252 #--------------------------------------------------------------------------
253 $ComTab{'H'}=[ 2, '', \&Emit, '{ $Hold .= "\n"; $Hold .= $_; }' ]; #ok
257 Append a newline and the contents of the pattern space to the hold space.
261 #--------------------------------------------------------------------------
262 $ComTab{'i'}=[ 1, 'txt', \&Emit, '{ print <<'."'TheEnd' }\n" ]; #ok
264 =item [1addr]B<i\> I<text>
266 Write the I<text> (which must start on the line following the command)
271 #--------------------------------------------------------------------------
272 $ComTab{'l'}=[ 2, '', \&Emit, '{ _l() }' ]; #okUTF8
276 Print the contents of the pattern space: non-printable characters are
277 shown in C-style escaped form; long lines are split and have a trailing
278 `C<\>' at the point of the split; the true end of a line is marked with
279 a `C<$>'. Escapes are: `\a', `\t', `\n', `\f', `\r', `\e' for
280 BEL, HT, LF, FF, CR, ESC, respectively, and `\' followed by a three-digit
281 octal number for all other non-printable characters.
285 #--------------------------------------------------------------------------
286 $ComTab{'n'}=[ 2, '', \&Emit, <<'-X-' ]; #ok
287 { print $_, "\n" if $doPrint;
290 last CYCLE unless getsARGV();
297 If automatic printing is enabled, write the pattern space to the standard
298 output. Replace the pattern space with the next line of input. If
299 there is no more input, processing is terminated.
303 #--------------------------------------------------------------------------
304 $ComTab{'N'}=[ 2, '', \&Emit, <<'-X-' ]; #ok
307 last CYCLE unless getsARGV( $h );
315 Append a newline and the next line of input to the pattern space. If
316 there is no more input, processing is terminated.
320 #--------------------------------------------------------------------------
321 $ComTab{'p'}=[ 2, '', \&Emit, '{ print $_, "\n"; }' ]; #ok
325 Print the pattern space to the standard output. (Use the B<-n> option
326 to suppress automatic printing at the end of a cycle if you want to
327 avoid double printing of lines.)
331 #--------------------------------------------------------------------------
332 $ComTab{'P'}=[ 2, '', \&Emit, <<'-X-' ]; #ok
333 { if( /^(.*)/ ){ print $1, "\n"; } }
338 Prints the pattern space through the first embedded newline or to the end.
342 #--------------------------------------------------------------------------
343 $ComTab{'q'}=[ 1, 'str', \&Emit, <<'-X-' ]; #ok
344 { print $_, "\n" if $doPrint;
352 Branch to the end of the script and quit without starting a new cycle.
356 #--------------------------------------------------------------------------
357 $ComTab{'r'}=[ 1, 'str', \&Emit, "{ _r( '-X-' ) }" ]; #ok
359 =item [1addr]B<r> I<file>
361 Copy the contents of the I<file> to standard output immediately before
362 the next attempt to read a line of input. Any error encountered while
363 reading I<file> is silently ignored.
367 #--------------------------------------------------------------------------
368 $ComTab{'s'}=[ 2, 'sub', \&Emit, '' ]; #ok
370 =item [2addr]B<s/>I<regular expression>B</>I<replacement>B</>I<flags>
372 Substitute the I<replacement> string for the first substring in
373 the pattern space that matches the I<regular expression>.
374 Any character other than backslash or newline can be used instead of a
375 slash to delimit the regular expression and the replacement.
376 To use the delimiter as a literal character within the regular expression
377 and the replacement, precede the character by a backslash (`C<\>').
379 Literal newlines may be embedded in the replacement string by
380 preceding a newline with a backslash.
382 Within the replacement, an ampersand (`C<&>') is replaced by the string
383 matching the regular expression. The strings `C<\1>' through `C<\9>' are
384 replaced by the corresponding subpattern (see L<"Basic Regular Expressions">).
385 To get a literal `C<&>' or `C<\>' in the replacement text, precede it
388 The following I<flags> modify the behaviour of the B<s> command:
394 The replacement is performed for all matching, non-overlapping substrings
395 of the pattern space.
399 Replace only the n-th matching substring of the pattern space.
403 If the substitution was made, print the new value of the pattern space.
407 If the substitution was made, write the new value of the pattern space
408 to the specified file.
414 #--------------------------------------------------------------------------
415 $ComTab{'t'}=[ 2, 'str', \&Branch, '{ goto XXX if _t() }' ]; #ok
417 =item [2addr]B<t> [I<label>]
419 Branch to the B<:> function with the specified I<label> if any B<s>
420 substitutions have been made since the most recent reading of an input line
421 or execution of a B<t> function. If no label is given, branch to the end of
427 #--------------------------------------------------------------------------
428 $ComTab{'w'}=[ 2, 'str', \&Write, "{ _w( '-X-' ) }" ]; #ok
430 =item [2addr]B<w> I<file>
432 The contents of the pattern space are written to the I<file>.
436 #--------------------------------------------------------------------------
437 $ComTab{'x'}=[ 2, '', \&Emit, '{ ($Hold, $_) = ($_, $Hold) }' ]; #ok
441 Swap the contents of the pattern space and the hold space.
445 #--------------------------------------------------------------------------
446 $ComTab{'y'}=[ 2, 'tra', \&Emit, '' ]; #ok
447 =item [2addr]B<y>B</>I<string1>B</>I<string2>B</>
449 In the pattern space, replace all characters occuring in I<string1> by the
450 character at the corresponding position in I<string2>. It is possible
451 to use any character (other than a backslash or newline) instead of a
452 slash to delimit the strings. Within I<string1> and I<string2>, a
453 backslash followed by any character other than a newline is that literal
454 character, and a backslash followed by an `n' is replaced by a newline
459 #--------------------------------------------------------------------------
460 $ComTab{'='}=[ 1, '', \&Emit, '{ print "$.\n" }' ]; #ok
464 Prints the current line number on the standard output.
468 #--------------------------------------------------------------------------
469 $ComTab{':'}=[ 0, 'str', \&Label, '' ]; #ok
471 =item [0addr]B<:> [I<label>]
473 The command specifies the position of the I<label>. It has no other effect.
477 #--------------------------------------------------------------------------
478 $ComTab{'{'}=[ 2, '', \&BeginBlock, '{' ]; #ok
479 $ComTab{'}'}=[ 0, '', \&EndBlock, ';}' ]; #ok
480 # ';' to avoid warning on empty {}-block
482 =item [2addr]B<{> [I<command>]
486 These two commands begin and end a command list. The first command may
487 be given on the same line as the opening B<{> command. The commands
488 within the list are jointly selected by the address(es) given on the
489 B<{> command (but may still have individual addresses).
493 #--------------------------------------------------------------------------
494 $ComTab{'#'}=[ 0, 'str', \&Comment, '' ]; #ok
496 =item [0addr]B<#> [I<comment>]
498 The entire line is ignored (treated as a comment). If, however, the first
499 two characters in the script are `C<#n>', automatic printing of output is
500 suppressed, as if the B<-n> option were given on the command line.
506 use vars qw{ $isEOF $Hold %wFiles @Q $CondReg $doPrint };
508 my $useDEBUG = exists( $ENV{PSEDDEBUG} );
509 my $useEXTBRE = $ENV{PSEDEXTBRE} || '';
510 $useEXTBRE =~ s/[^<>wWyB]//g; # gawk RE's handle these
512 my $doAutoPrint = 1; # automatic printing of pattern space (-n => 0)
513 my $doOpenWrite = 1; # open w command output files at start (-a => 0)
514 my $svOpenWrite = 0; # save $doOpenWrite
516 # lower case $0 below as a VMSism. The VMS build procedure creates the
517 # s2p file traditionally in upper case on the disk. When VMS is in a
518 # case preserved or case sensitive mode, $0 will be returned in the exact
519 # case which will be on the disk, and that is not predictable at this time.
521 my $doGenerate = lc($0) eq 's2p';
523 # Collected and compiled script
525 my( @Commands, %Defined, @BlockStack, %Label, $labNum, $Code, $Func );
536 my( $msg, $loc ) = @_;
538 $loc .= ': ' if length( $loc );
539 warn( "$0: $loc$msg\n" );
544 return 'L_'.++$labNum;
547 # safeHere: create safe here delimiter and modify opcode and argument
550 my( $codref, $argref ) = @_;
552 while( $$argref =~ /^$eod$/m ){
555 $$codref =~ s/TheEnd/$eod/e;
556 $$argref .= "$eod\n";
559 # Emit: create address logic and emit command
562 my( $addr1, $addr2, $negated, $opcode, $arg, $fl ) = @_;
564 if( defined( $addr1 ) ){
565 if( defined( $addr2 ) ){
566 $addr1 .= $addr2 =~ /^\d+$/ ? "..$addr2" : "...$addr2";
568 $addr1 .= ' == $.' if $addr1 =~ /^\d+$/;
570 $cond = $negated ? "unless( $addr1 )\n" : "if( $addr1 )\n";
574 $Code .= "$cond$arg\n";
576 } elsif( $opcode =~ s/-X-/$arg/e ){
577 $Code .= "$cond$opcode\n";
579 } elsif( $opcode =~ /TheEnd/ ){
580 safeHere( \$opcode, \$arg );
581 $Code .= "$cond$opcode$arg";
584 $Code .= "$cond$opcode\n";
589 # Write (w command, w flag): store pathname
592 my( $addr1, $addr2, $negated, $opcode, $path, $fl ) = @_;
594 Emit( $addr1, $addr2, $negated, $opcode, $path, $fl );
598 # Label (: command): label definition
601 my( $addr1, $addr2, $negated, $opcode, $lab, $fl ) = @_;
604 if( length( $lab ) ){
606 if( ! exists( $Label{$lab} ) ){
607 $h = $Label{$lab}{name} = newLabel();
609 $h = $Label{$lab}{name};
610 if( exists( $Label{$lab}{defined} ) ){
611 my $dl = $Label{$lab}{defined};
612 Warn( "duplicate label $lab (first defined at $dl)", $fl );
616 $Label{$lab}{defined} = $fl;
622 # BeginBlock ({ command): push block start
624 sub BeginBlock($$$$$$){
625 my( $addr1, $addr2, $negated, $opcode, $arg, $fl ) = @_;
626 push( @BlockStack, [ $fl, $addr1, $addr2, $negated ] );
627 Emit( $addr1, $addr2, $negated, $opcode, $arg, $fl );
630 # EndBlock (} command): check proper nesting
632 sub EndBlock($$$$$$){
633 my( $addr1, $addr2, $negated, $opcode, $arg, $fl ) = @_;
635 my $jcom = pop( @BlockStack );
636 if( defined( $jcom ) ){
637 $rc = Emit( $addr1, $addr2, $negated, $opcode, $arg, $fl );
639 Warn( "unexpected `}'", $fl );
645 # Branch (t, b commands): check or create label, substitute default
648 my( $addr1, $addr2, $negated, $opcode, $lab, $fl ) = @_;
649 $lab =~ s/\s+//; # no spaces at end
651 if( length( $lab ) ){
652 if( ! exists( $Label{$lab} ) ){
653 $h = $Label{$lab}{name} = newLabel();
655 $h = $Label{$lab}{name};
657 push( @{$Label{$lab}{used}}, $fl );
661 $opcode =~ s/XXX/$h/e;
662 Emit( $addr1, $addr2, $negated, $opcode, '', $fl );
665 # Change (c command): is special due to range end watching
668 my( $addr1, $addr2, $negated, $opcode, $arg, $fl ) = @_;
669 my $kwd = $negated ? 'unless' : 'if';
670 if( defined( $addr2 ) ){
671 $addr1 .= $addr2 =~ /^\d+$/ ? "..$addr2" : "...$addr2";
673 $addr1 = '$icnt = ('.$addr1.')';
674 $opcode = 'if( $icnt =~ /E0$/ )' . $opcode;
677 $addr1 .= ' == $.' if $addr1 =~ /^\d+$/;
679 safeHere( \$opcode, \$arg );
680 $Code .= "$kwd( $addr1 ){\n $opcode$arg}\n";
685 # Comment (# command): A no-op. Who would've thought that!
688 my( $addr1, $addr2, $negated, $opcode, $arg, $fl ) = @_;
689 ### $Code .= "# $arg\n";
693 # stripRegex from the current command. If we're in the first
694 # part of s///, trailing spaces have to be kept as the initial
695 # part of the replacement string.
697 sub stripRegex($$;$){
698 my( $del, $sref, $sub ) = @_;
700 print "stripRegex:$del:$$sref:\n" if $useDEBUG;
701 while( $$sref =~ s{^(.*?)(\\*)\Q$del\E(\s*)}{}s ){
702 my ($lead, $sl, $rest) = ($1, $2, $3);
703 $regex .= $lead.$sl.$del;
704 if( !($lead =~ /(?:^|[^\\])\[^?\]?[^]]*$/) && length( $sl ) % 2 == 0 ){
705 if( $sub && (length( $rest ) > 0) ){
706 $$sref = $rest . $$sref;
715 # stripTrans: take a <del> terminated string from y command
716 # honoring and cleaning up of \-escaped <del>'s
719 my( $del, $sref ) = @_;
721 print "stripTrans:$del:$$sref:\n" if $useDEBUG;
722 while( $$sref =~ s{^(.*?)(\\*)\Q$del\E}{}s ){
725 if( length( $sl ) % 2 == 0 ){
736 # makey - construct Perl y/// from sed y///
739 my( $fr, $to, $fl ) = @_;
742 # Ensure that any '-' is up front.
743 # Diagnose duplicate contradicting mappings
745 for( my $i = 0; $i < length($fr); $i++ ){
746 my $fc = substr($fr,$i,1);
747 my $tc = substr($to,$i,1);
748 if( exists( $tr{$fc} ) && $tr{$fc} ne $tc ){
749 Warn( "ambiguous translation for character `$fc' in `y' command",
756 if( exists( $tr{'-'} ) ){
757 ( $fr, $to ) = ( '-', $tr{'-'} );
762 # might just as well sort it...
763 for my $fc ( sort keys( %tr ) ){
767 # make embedded delimiters and newlines safe
768 $fr =~ s/([{}])/\$1/g;
769 $to =~ s/([{}])/\$1/g;
772 return $error ? undef() : "{ y{$fr}{$to}; }";
776 # makes - construct Perl s/// from sed s///
779 my( $regex, $subst, $path, $global, $print, $nmatch, $fl ) = @_;
781 # make embedded newlines safe
782 $regex =~ s/\n/\\n/g;
783 $subst =~ s/\n/\\n/g;
788 if( length( $nmatch ) ){
791 while( --\$n && ( \$s = m ${regex}g ) ){}
792 \$s = ( substr( \$_, pos() ) =~ s ${regex}${subst}s ) if \$s;
797 { \$s = s ${regex}${subst}s${global};
802 $code .= ' print $_, "\n" if $s;'."\n";
804 if( defined( $path ) ){
806 $code .= " _w( '$path' ) if \$s;\n";
812 =head1 BASIC REGULAR EXPRESSIONS
814 A I<Basic Regular Expression> (BRE), as defined in POSIX 1003.2, consists
815 of I<atoms>, for matching parts of a string, and I<bounds>, specifying
816 repetitions of a preceding atom.
820 The possible atoms of a BRE are: B<.>, matching any single character;
821 B<^> and B<$>, matching the null string at the beginning or end
822 of a string, respectively; a I<bracket expressions>, enclosed
823 in B<[> and B<]> (see below); and any single character with no
824 other significance (matching that character). A B<\> before one
825 of: B<.>, B<^>, B<$>, B<[>, B<*>, B<\>, matching the character
826 after the backslash. A sequence of atoms enclosed in B<\(> and B<\)>
827 becomes an atom and establishes the target for a I<backreference>,
828 consisting of the substring that actually matches the enclosed atoms.
829 Finally, B<\> followed by one of the digits B<0> through B<9> is a
832 A B<^> that is not first, or a B<$> that is not last does not have
833 a special significance and need not be preceded by a backslash to
834 become literal. The same is true for a B<]>, that does not terminate
835 a bracket expression.
837 An unescaped backslash cannot be last in a BRE.
841 The BRE bounds are: B<*>, specifying 0 or more matches of the preceding
842 atom; B<\{>I<count>B<\}>, specifying that many repetitions;
843 B<\{>I<minimum>B<,\}>, giving a lower limit; and
844 B<\{>I<minimum>B<,>I<maximum>B<\}> finally defines a lower and upper
847 A bound appearing as the first item in a BRE is taken literally.
849 =head2 Bracket Expressions
851 A I<bracket expression> is a list of characters, character ranges
852 and character classes enclosed in B<[> and B<]> and matches any
853 single character from the represented set of characters.
855 A character range is written as two characters separated by B<-> and
856 represents all characters (according to the character collating sequence)
857 that are not less than the first and not greater than the second.
858 (Ranges are very collating-sequence-dependent, and portable programs
859 should avoid relying on them.)
861 A character class is one of the class names
868 enclosed in B<[:> and B<:]> and represents the set of characters
869 as defined in ctype(3).
871 If the first character after B<[> is B<^>, the sense of matching is
874 To include a literal `C<^>', place it anywhere else but first. To
875 include a literal 'C<]>' place it first or immediately after an
876 initial B<^>. To include a literal `C<->' make it the first (or
877 second after B<^>) or last character, or the second endpoint of
880 The special bracket expression constructs C<[[:E<lt>:]]> and C<[[:E<gt>:]]>
881 match the null string at the beginning and end of a word respectively.
882 (Note that neither is identical to Perl's `\b' atom.)
884 =head2 Additional Atoms
886 Since some sed implementations provide additional regular expression
887 atoms (not defined in POSIX 1003.2), B<psed> is capable of translating
888 the following backslash escapes:
892 =item B<\E<lt>> This is the same as C<[[:E<gt>:]]>.
894 =item B<\E<gt>> This is the same as C<[[:E<lt>:]]>.
896 =item B<\w> This is an abbreviation for C<[[:alnum:]_]>.
898 =item B<\W> This is an abbreviation for C<[^[:alnum:]_]>.
900 =item B<\y> Match the empty string at a word boundary.
902 =item B<\B> Match the empty string between any two either word or non-word characters.
906 To enable this feature, the environment variable PSEDEXTBRE must be set
907 to a string containing the requested characters, e.g.:
908 C<PSEDEXTBRE='E<lt>E<gt>wW'>.
913 # bre2p - convert BRE to Perl RE
916 my( $pref, $ic ) = @_;
917 $ic < length($$pref)-1 ? substr( $$pref, $ic+1, 1 ) : '';
921 my( $del, $pat, $fl ) = @_;
923 $led =~ tr/{([</})]>/;
924 $led = '' if $led eq $del;
926 $pat = substr( $pat, 1, length($pat) - 2 );
931 for( my $ic = 0; $ic < length( $pat ); $ic++ ){
932 my $c = substr( $pat, $ic, 1 );
934 ### backslash escapes
935 my $nc = peek($pat,$ic);
937 Warn( "`\\' cannot be last in pattern", $fl );
941 if( $nc eq $del ){ ## \<pattern del> => \<pattern del>
944 } elsif( $nc =~ /([[.*\\n])/ ){
945 ## check for \-escaped magics and \n:
946 ## \[ \. \* \\ \n stay as they are
949 } elsif( $nc eq '(' ){ ## \( => (
953 } elsif( $nc eq ')' ){ ## \) => )
957 Warn( "unmatched `\\)'", $fl );
962 } elsif( $nc eq '{' ){ ## repetition factor \{<i>[,[<j>]]\}
963 my $endpos = index( $pat, '\\}', $ic );
965 Warn( "unmatched `\\{'", $fl );
968 my $rep = substr( $pat, $ic+1, $endpos-($ic+1) );
971 if( $res =~ /^\^?$/ ){
973 } elsif( $rep =~ /^(\d+)(,?)(\d*)?$/ ){
977 if( length( $max ) ){
979 Warn( "maximum less than minimum in `\\{$rep\\}'",
987 if( $min == 0 && $max eq '1' ){
989 } elsif( $min == 1 && "$com$max" eq ',' ){
991 } elsif( $min == 0 && "$com$max" eq ',' ){
994 $res .= "{$min$com$max}";
997 Warn( "invalid repeat clause `\\{$rep\\}'", $fl );
1001 } elsif( $nc =~ /^[1-9]$/ ){
1002 ## \1 .. \9 => \1 .. \9, but check for a following digit
1003 if( $nc > $backref ){
1004 Warn( "invalid backreference ($nc)", $fl );
1008 if( peek($pat,$ic) =~ /[0-9]/ ){
1012 } elsif( $useEXTBRE && ( $nc =~ /[$useEXTBRE]/ ) ){
1013 ## extensions - at most <>wWyB - not in POSIX
1014 if( $nc eq '<' ){ ## \< => \b(?=\w), be precise
1015 $res .= '\\b(?<=\\W)';
1016 } elsif( $nc eq '>' ){ ## \> => \b(?=\W), be precise
1017 $res .= '\\b(?=\\W)';
1018 } elsif( $nc eq 'y' ){ ## \y => \b
1020 } else { ## \B, \w, \W remain the same
1023 } elsif( $nc eq $led ){
1024 ## \<closing bracketing-delimiter> - keep '\'
1027 } else { ## \ <char> => <char> ("as if `\' were not present")
1031 } elsif( $c eq '.' ){ ## . => .
1034 } elsif( $c eq '*' ){ ## * => * but \* if there's nothing preceding it
1035 if( $res =~ /^\^?$/ ){
1037 } elsif( substr( $res, -1, 1 ) ne '*' ){
1041 } elsif( $c eq '[' ){
1042 ## parse []: [^...] [^]...] [-...]
1044 if( peek($pat,$ic) eq '^' ){
1048 my $nc = peek($pat,$ic);
1049 if( $nc eq ']' || $nc eq '-' ){
1053 # check that [ is not trailing
1054 if( $ic >= length( $pat ) - 1 ){
1055 Warn( "unmatched `['", $fl );
1058 # look for [:...:] and x-y
1059 my $rstr = substr( $pat, $ic+1 );
1060 if( $rstr =~ /^((?:\[:\(\w+|[><]\):\]|[^]-](?:-[^]])?)*)/ ){
1062 $ic += length( $cnt );
1063 $cnt =~ s/([\/\$])/\\$1/g; # `/', `$' are magic in Perl []
1064 # try some simplifications
1066 if( $red =~ s/0-9// ){
1068 if( $red =~ s/A-Z// && $red =~ s/a-z// && $red =~ s/_// ){
1074 # POSIX 1003.2 has this (optional) for begin/end word
1075 $add = '\\b(?=\\W)' if $add eq '[[:<:]]';
1076 $add = '\\b(?<=\\W)' if $add eq '[[:>:]]';
1080 ## may have a trailing `-' before `]'
1081 if( $ic < length($pat) - 1 &&
1082 substr( $pat, $ic+1 ) =~ /^(-?])/ ){
1083 $ic += length( $1 );
1085 # another simplification
1086 $add =~ s/^\[(\^?)(\\[dw])]$/ $1 eq '^' ? uc($2) : $2 /e;
1089 Warn( "unmatched `['", $fl );
1093 } elsif( $c eq $led ){ ## unescaped <closing bracketing-delimiter>
1096 } elsif( $c eq ']' ){ ## unmatched ] is not magic
1099 } elsif( $c =~ /[|+?{}()@#\/]/ ){ ## not magic in BRE, but in Perl: \-quote
1102 } elsif( $c eq '^' ){ ## not magic unless 1st, but in Perl: \-quote
1103 $res .= length( $res ) ? '\\^' : '^';
1105 } elsif( $c eq '$' ){ ## not magic unless last, but in Perl: \-quote
1106 $res .= $ic == length( $pat ) - 1 ? '$' : '\\$';
1114 Warn( "unmatched `\\('", $fl );
1118 # final cleanup: eliminate raw HTs
1120 return $del . $res . ( $led ? $led : $del );
1125 # sub2p - convert sed substitution to Perl substitution
1128 my( $del, $subst, $fl ) = @_;
1130 $led =~ tr/{([</})]>/;
1131 $led = '' if $led eq $del;
1133 $subst = substr( $subst, 1, length($subst) - 2 );
1136 for( my $ic = 0; $ic < length( $subst ); $ic++ ){
1137 my $c = substr( $subst, $ic, 1 );
1139 ### backslash escapes
1140 my $nc = peek($subst,$ic);
1142 Warn( "`\\' cannot be last in substitution", $fl );
1146 if( $nc =~ /[\\$del$led]/ ){ ## \ and delimiter
1148 } elsif( $nc =~ /[1-9]/ ){ ## \1 - \9 => ${1} - ${9}
1149 $res .= '${' . $nc . '}';
1150 } else { ## everything else (includes &): omit \
1153 } elsif( $c eq '&' ){ ## & => $&
1155 } elsif( $c =~ /[\$\@$led]/ ){ ## magic in Perl's substitution string
1162 # final cleanup: eliminate raw HTs
1164 return ( $led ? $del : $led ) . $res . ( $led ? $led : $del );
1170 my( $pdef, $pfil, $plin );
1171 for( my $icom = 0; $icom < @Commands; $icom++ ){
1172 my $cmd = $Commands[$icom];
1173 print "Parse:$cmd:\n" if $useDEBUG;
1175 next unless length( $cmd );
1177 if( exists( $Defined{$icom} ) ){
1178 $pdef = $Defined{$icom};
1179 if( $pdef =~ /^ #(\d+)/ ){
1180 $pfil = 'expression #';
1189 my $fl = "$pfil$plin";
1191 # insert command as comment in gnerated code
1193 $Code .= "# $cmd\n" if $doGenerate;
1197 my( $negated, $naddr, $addr1, $addr2 );
1199 if( $cmd =~ s/^(\d+)\s*// ){
1200 $addr1 = "$1"; $naddr++;
1201 } elsif( $cmd =~ s/^\$\s*// ){
1202 $addr1 = 'eofARGV()'; $naddr++;
1203 } elsif( $cmd =~ s{^(/)}{} || $cmd =~ s{^\\(.)}{} ){
1205 my $regex = stripRegex( $del, \$cmd );
1206 if( defined( $regex ) ){
1207 $addr1 = 'm '.bre2p( $del, $regex, $fl ).'s';
1210 Warn( "malformed regex, 1st address", $fl );
1215 if( defined( $addr1 ) && $cmd =~ s/,\s*// ){
1216 if( $cmd =~ s/^(\d+)\s*// ){
1217 $addr2 = "$1"; $naddr++;
1218 } elsif( $cmd =~ s/^\$\s*// ){
1219 $addr2 = 'eofARGV()'; $naddr++;
1220 } elsif( $cmd =~ s{^(/)}{} || $cmd =~ s{^\\(.)}{} ){
1222 my $regex = stripRegex( $del, \$cmd );
1223 if( defined( $regex ) ){
1224 $addr2 = 'm '. bre2p( $del, $regex, $fl ).'s';
1227 Warn( "malformed regex, 2nd address", $fl );
1232 Warn( "invalid address after `,'", $fl );
1238 # address modifier `!'
1240 $negated = $cmd =~ s/^!\s*//;
1241 if( defined( $addr1 ) ){
1242 print "Parse: addr1=$addr1" if $useDEBUG;
1243 if( defined( $addr2 ) ){
1244 print ", addr2=$addr2 " if $useDEBUG;
1245 # both numeric and addr1 > addr2 => eliminate addr2
1246 undef( $addr2 ) if $addr1 =~ /^\d+$/ &&
1247 $addr2 =~ /^\d+$/ && $addr1 > $addr2;
1250 print 'negated' if $useDEBUG && $negated;
1251 print " command:$cmd\n" if $useDEBUG;
1255 if( $cmd !~ s/^([:#={}abcdDgGhHilnNpPqrstwxy])\s*// ){
1256 my $h = substr( $cmd, 0, 1 );
1257 Warn( "unknown command `$h'", $fl );
1263 my $tabref = $ComTab{$key};
1265 if( $naddr > $tabref->[0] ){
1266 Warn( "excess address(es)", $fl );
1272 if( $tabref->[1] eq 'str' ){
1273 # take remainder - don't care if it is empty
1277 } elsif( $tabref->[1] eq 'txt' ){
1279 my $goon = $cmd =~ /(.*)\\$/;
1281 Warn( "extra characters after command ($cmd)", $fl );
1286 if( $icom > $#Commands ){
1287 Warn( "unexpected end of script", $fl );
1291 $cmd = $Commands[$icom];
1292 $Code .= "# $cmd\n" if $doGenerate;
1293 $goon = $cmd =~ s/\\$//;
1294 $cmd =~ s/\\(.)/$1/g;
1295 $arg .= "\n" if length( $arg );
1298 $arg .= "\n" if length( $arg );
1301 } elsif( $tabref->[1] eq 'sub' ){
1303 if( ! length( $cmd ) ){
1304 Warn( "`s' command requires argument", $fl );
1308 if( $cmd =~ s{^([^\\\n])}{} ){
1310 my $regex = stripRegex( $del, \$cmd, "s" );
1311 if( ! defined( $regex ) ){
1312 Warn( "malformed regular expression", $fl );
1316 $regex = bre2p( $del, $regex, $fl );
1318 # a trailing \ indicates embedded NL (in replacement string)
1319 while( $cmd =~ s/(?<!\\)\\$/\n/ ){
1321 if( $icom > $#Commands ){
1322 Warn( "unexpected end of script", $fl );
1326 $cmd .= $Commands[$icom];
1327 $Code .= "# $Commands[$icom]\n" if $doGenerate;
1330 my $subst = stripRegex( $del, \$cmd );
1331 if( ! defined( $regex ) ){
1332 Warn( "malformed substitution expression", $fl );
1336 $subst = sub2p( $del, $subst, $fl );
1338 # parse s/// modifier: g|p|0-9|w <file>
1339 my( $global, $nmatch, $print, $write ) =
1340 ( '', '', 0, undef );
1341 while( $cmd =~ s/^([gp0-9])// ){
1342 $1 eq 'g' ? ( $global = 'g' ) :
1343 $1 eq 'p' ? ( $print = $1 ) : ( $nmatch .= $1 );
1345 $write = $1 if $cmd =~ s/w\s*(.*)$//;
1346 ### $nmatch =~ s/^(\d)\1*$/$1/; ### may be dangerous?
1347 if( $global && length( $nmatch ) || length( $nmatch ) > 1 ){
1348 Warn( "conflicting flags `$global$nmatch'", $fl );
1353 $arg = makes( $regex, $subst,
1354 $write, $global, $print, $nmatch, $fl );
1355 if( ! defined( $arg ) ){
1361 Warn( "improper delimiter in s command", $fl );
1366 } elsif( $tabref->[1] eq 'tra' ){
1368 # a trailing \ indicates embedded newline
1369 while( $cmd =~ s/(?<!\\)\\$/\n/ ){
1371 if( $icom > $#Commands ){
1372 Warn( "unexpected end of script", $fl );
1376 $cmd .= $Commands[$icom];
1377 $Code .= "# $Commands[$icom]\n" if $doGenerate;
1379 if( ! length( $cmd ) ){
1380 Warn( "`y' command requires argument", $fl );
1384 my $d = substr( $cmd, 0, 1 ); $cmd = substr( $cmd, 1 );
1386 Warn( "`\\' not valid as delimiter in `y' command", $fl );
1390 my $fr = stripTrans( $d, \$cmd );
1391 if( ! defined( $fr ) || ! length( $cmd ) ){
1392 Warn( "malformed `y' command argument", $fl );
1396 my $to = stripTrans( $d, \$cmd );
1397 if( ! defined( $to ) ){
1398 Warn( "malformed `y' command argument", $fl );
1402 if( length($fr) != length($to) ){
1403 Warn( "string lengths in `y' command differ", $fl );
1407 if( ! defined( $arg = makey( $fr, $to, $fl ) ) ){
1414 # $cmd must be now empty - exception is {
1415 if( $cmd !~ /^\s*$/ ){
1417 # dirty hack to process command on '{' line
1418 $Commands[$icom--] = $cmd;
1420 Warn( "extra characters after command ($cmd)", $fl );
1428 if( &{$tabref->[2]}( $addr1, $addr2, $negated,
1429 $tabref->[3], $arg, $fl ) ){
1434 while( @BlockStack ){
1435 my $bl = pop( @BlockStack );
1436 Warn( "start of unterminated `{'", $bl );
1440 for my $lab ( keys( %Label ) ){
1441 if( ! exists( $Label{$lab}{defined} ) ){
1442 for my $used ( @{$Label{$lab}{used}} ){
1443 Warn( "undefined label `$lab'", $used );
1449 exit( 1 ) if $error;
1458 print STDERR "Usage: sed [-an] command [file...]\n";
1459 print STDERR " [-an] [-e command] [-f script-file] [file...]\n";
1463 # Here we go again...
1466 while( @ARGV && $ARGV[0] =~ /^-(.)(.*)$/ ){
1471 if( length( $arg ) ){
1472 push( @Commands, split( "\n", $arg ) );
1474 push( @Commands, shift( @ARGV ) );
1476 Warn( "option -e requires an argument" );
1481 $Defined{$#Commands} = " #$expr";
1486 if( length( $arg ) ){
1489 $path = shift( @ARGV );
1491 Warn( "option -f requires an argument" );
1495 my $fst = $#Commands + 1;
1496 open( SCRIPT, "<$path" ) || die( "$0: $path: could not open ($!)\n" );
1498 while( defined( $cmd = <SCRIPT> ) ){
1500 push( @Commands, $cmd );
1503 if( $#Commands >= $fst ){
1504 $Defined{$fst} = "$path";
1508 if( $opt eq '-' && $arg eq '' ){
1511 if( $opt eq 'h' || $opt eq '?' ){
1517 } elsif( $opt eq 'a' ){
1520 Warn( "illegal option `$opt'" );
1524 if( length( $arg ) ){
1525 unshift( @ARGV, "-$arg" );
1529 # A singleton command may be the 1st argument when there are no options.
1531 if( @Commands == 0 ){
1533 Warn( "no script command given" );
1537 push( @Commands, split( "\n", shift( @ARGV ) ) );
1538 $Defined{0} = ' #1';
1541 print STDERR "Files: @ARGV\n" if $useDEBUG;
1543 # generate leading code
1545 $Func = <<'[TheEnd]';
1547 # openARGV: open 1st input file
1550 unshift( @ARGV, '-' ) unless @ARGV;
1551 my $file = shift( @ARGV );
1552 open( ARG, "<$file" )
1553 || die( "$0: can't open $file for reading ($!)\n" );
1557 # getsARGV: Read another input line into argument (default: $_).
1558 # Move on to next input file, and reset EOF flag $isEOF.
1560 my $argref = @_ ? shift() : \$_;
1561 while( $isEOF || ! defined( $$argref = <ARG> ) ){
1563 return 0 unless @ARGV;
1564 my $file = shift( @ARGV );
1565 open( ARG, "<$file" )
1566 || die( "$0: can't open $file for reading ($!)\n" );
1572 # eofARGV: end-of-file test
1575 return @ARGV == 0 && ( $isEOF = eof( ARG ) );
1578 # makeHandle: Generates another file handle for some file (given by its path)
1579 # to be written due to a w command or an s command's w flag.
1583 if( ! exists( $wFiles{$path} ) || $wFiles{$path} eq '' ){
1584 $handle = $wFiles{$path} = gensym();
1586 if( ! open( $handle, ">$path" ) ){
1587 die( "$0: can't open $path for writing: ($!)\n" );
1591 $handle = $wFiles{$path};
1596 # printQ: Print queued output which is either a string or a reference
1601 # flush open w files so that reading this file gets it all
1602 if( exists( $wFiles{$$q} ) && $wFiles{$$q} ne '' ){
1603 open( $wFiles{$$q}, ">>$$q" );
1605 # copy file to stdout: slow, but safe
1606 if( open( RF, "<$$q" ) ){
1607 while( defined( my $line = <RF> ) ){
1621 # generate the sed loop
1623 $Code .= <<'[TheEnd]';
1629 # Run: the sed loop reading input and applying the script
1632 my( $h, $icnt, $s, $n );
1633 # hack (not unbreakable :-/) to avoid // matching an empty string
1634 my $z = "\000"; $z =~ /$z/;
1640 $doPrint = $doAutoPrint;
1642 while( getsARGV() ){
1644 $CondReg = 0; # cleared on t
1648 # parse - avoid opening files when doing s2p
1650 ( $svOpenWrite, $doOpenWrite ) = ( $doOpenWrite, $svOpenWrite )
1653 ( $svOpenWrite, $doOpenWrite ) = ( $doOpenWrite, $svOpenWrite )
1656 # append trailing code
1658 $Code .= <<'[TheEnd]';
1659 EOS: if( $doPrint ){
1662 $doPrint = $doAutoPrint;
1667 exit( $exitstatus );
1672 # append optional functions, prepend prototypes
1674 my $Proto = "# prototypes\n";
1676 $Proto .= "sub _l();\n";
1677 $Func .= <<'[TheEnd]';
1678 # _l: l command processing
1683 # transform non printing chars into escape notation
1685 if( $h =~ /[^[:print:]]/ ){
1692 $h =~ s/([^[:print:]])/sprintf("\\%03o", ord($1))/ge;
1694 # split into lines of length $mcpl
1695 while( length( $h ) > $mcpl ){
1696 my $l = substr( $h, 0, $mcpl-1 );
1697 $h = substr( $h, $mcpl );
1698 # remove incomplete \-escape from end of line
1699 if( $l =~ s/(?<!\\)(\\[0-7]{0,2})$// ){
1711 $Proto .= "sub _r(\$);\n";
1712 $Func .= <<'[TheEnd]';
1713 # _r: r command processing: Save a reference to the pathname.
1724 $Proto .= "sub _t();\n";
1725 $Func .= <<'[TheEnd]';
1726 # _t: t command - condition register test/reset
1738 $Proto .= "sub _w(\$);\n";
1739 $Func .= <<'[TheEnd]';
1740 # _w: w command and s command's w flag - write to file
1744 my $handle = $wFiles{$path};
1745 if( ! $doOpenWrite && ! defined( fileno( $handle ) ) ){
1746 open( $handle, ">$path" )
1747 || die( "$0: $path: cannot open ($!)\n" );
1749 print $handle $_, "\n";
1755 $Code = $Proto . $Code;
1757 # magic "#n" - same as -n option
1759 $doAutoPrint = 0 if substr( $Commands[0], 0, 2 ) eq '#n';
1761 # eval code - check for errors
1763 print "Code:\n$Code$Func" if $useDEBUG;
1766 print "Code:\n$Code$Func";
1767 die( "$0: internal error - generated incorrect Perl code: $@\n" );
1772 # write full Perl program
1775 # bang line, declarations, prototypes
1778 eval 'exec $perlpath -S \$0 \${1+"\$@"}'
1780 \$0 =~ s/^.*?(\\w+)\[\\.\\w+\]*\$/\$1/;
1784 use vars qw{ \$isEOF \$Hold \%wFiles \@Q \$CondReg
1785 \$doAutoPrint \$doOpenWrite \$doPrint };
1786 \$doAutoPrint = $doAutoPrint;
1787 \$doOpenWrite = $doOpenWrite;
1790 my $wf = "'" . join( "', '", keys( %wFiles ) ) . "'";
1795 exit( 1 ) unless makeHandle( \$p );
1807 # execute: make handles (and optionally open) all w files; run!
1808 for my $p ( keys( %wFiles ) ){
1809 exit( 1 ) unless makeHandle( $p );
1817 The environment variable C<PSEDEXTBRE> may be set to extend BREs.
1818 See L<"Additional Atoms">.
1824 =item ambiguous translation for character `%s' in `y' command
1826 The indicated character appears twice, with different translations.
1828 =item `[' cannot be last in pattern
1830 A `[' in a BRE indicates the beginning of a I<bracket expression>.
1832 =item `\' cannot be last in pattern
1834 A `\' in a BRE is used to make the subsequent character literal.
1836 =item `\' cannot be last in substitution
1838 A `\' in a subsitution string is used to make the subsequent character literal.
1840 =item conflicting flags `%s'
1842 In an B<s> command, either the `g' flag and an n-th occurrence flag, or
1843 multiple n-th occurrence flags are specified. Note that only the digits
1844 `1' through `9' are permitted.
1846 =item duplicate label %s (first defined at %s)
1848 =item excess address(es)
1850 The command has more than the permitted number of addresses.
1852 =item extra characters after command (%s)
1854 =item illegal option `%s'
1856 =item improper delimiter in s command
1858 The BRE and substitution may not be delimited with `\' or newline.
1860 =item invalid address after `,'
1862 =item invalid backreference (%s)
1864 The specified backreference number exceeds the number of backreferences
1867 =item invalid repeat clause `\{%s\}'
1869 The repeat clause does not contain a valid integer value, or pair of
1872 =item malformed regex, 1st address
1874 =item malformed regex, 2nd address
1876 =item malformed regular expression
1878 =item malformed substitution expression
1880 =item malformed `y' command argument
1882 The first or second string of a B<y> command is syntactically incorrect.
1884 =item maximum less than minimum in `\{%s\}'
1886 =item no script command given
1888 There must be at least one B<-e> or one B<-f> option specifying a
1889 script or script file.
1891 =item `\' not valid as delimiter in `y' command
1893 =item option -e requires an argument
1895 =item option -f requires an argument
1897 =item `s' command requires argument
1899 =item start of unterminated `{'
1901 =item string lengths in `y' command differ
1903 The translation table strings in a B<y> command must have equal lengths.
1905 =item undefined label `%s'
1907 =item unexpected `}'
1909 A B<}> command without a preceding B<{> command was encountered.
1911 =item unexpected end of script
1913 The end of the script was reached although a text line after a
1914 B<a>, B<c> or B<i> command indicated another line.
1916 =item unknown command `%s'
1918 =item unterminated `['
1920 A BRE contains an unterminated bracket expression.
1922 =item unterminated `\('
1924 A BRE contains an unterminated backreference.
1926 =item `\{' without closing `\}'
1928 A BRE contains an unterminated bounds specification.
1930 =item `\)' without preceding `\('
1932 =item `y' command requires argument
1938 The basic material for the preceding section was generated by running
1942 s/^.*Warn( *"\([^"]*\)".*$/\1/
1947 s/$[_[:alnum:]]\{1,\}/%s/g
1952 on the program's own text, and piping the output into C<sort -u>.
1955 =head1 SED SCRIPT TRANSLATION
1957 If this program is invoked with the name F<s2p> it will act as a
1958 sed-to-Perl translator. After option processing (all other
1959 arguments are ignored), a Perl program is printed on standard
1960 output, which will process the input stream (as read from all
1961 arguments) in the way defined by the sed script and the option setting
1962 used for the translation.
1966 perl(1), re_format(7)
1970 The B<l> command will show escape characters (ESC) as `C<\e>', but
1971 a vertical tab (VT) in octal.
1973 Trailing spaces are truncated from labels in B<:>, B<t> and B<b> commands.
1975 The meaning of an empty regular expression (`C<//>'), as defined by B<sed>,
1976 is "the last pattern used, at run time". This deviates from the Perl
1977 interpretation, which will re-use the "last last successfully executed
1978 regular expression". Since keeping track of pattern usage would create
1979 terribly cluttered code, and differences would only appear in obscure
1980 context (where other B<sed> implementations appear to deviate, too),
1981 the Perl semantics was adopted. Note that common usage of this feature,
1982 such as in C</abc/s//xyz/>, will work as expected.
1984 Collating elements (of bracket expressions in BREs) are not implemented.
1988 This B<sed> implementation conforms to the IEEE Std1003.2-1992 ("POSIX.2")
1989 definition of B<sed>, and is compatible with the I<OpenBSD>
1990 implementation, except where otherwise noted (see L<"BUGS">).
1994 This Perl implementation of I<sed> was written by Wolfgang Laun,
1995 I<Wolfgang.Laun@alcatel.at>.
1997 =head1 COPYRIGHT and LICENSE
1999 This program is free and open software. You may use, modify,
2000 distribute, and sell this program (and any modified variants) in any
2001 way you wish, provided you do not restrict others from doing the same.