#! /usr/local/bin/perl -w # # TVM: read from stdin, output everything between $begin_pat and $end_pat # # Tim Mooney 12/17/98 use diagnostics; # use 5.004; $begin_pat=''; $in_pattern = 0; while (<>) { if (/$begin_pat(..*?)$end_pat(.*)$/ && ($in_pattern == 0) ) { # # handle the case where the begin tag & the end tag are on the same line # print $1; # now process anything after the $end_pat, so we handle multiple # occurrences of the tags on one line. $_ = $2; redo; } elsif (/$begin_pat(.*)$/ && ($in_pattern == 0) ) { $in_pattern=1; print $1; } elsif (/^(.*)$end_pat/ && ($in_pattern == 1) ) { $in_pattern=0; print $1; } elsif ( $in_pattern == 1 ) { # # print the entire line # print $_; } }