On Wed, Oct 22, 2003 at 12:59:33PM -0500, Jason wrote:
> I have a file formatted like this:

[ snip ]
 
> #error12
> #   Couldn't set the transfer mode to binary.
> #error12
> 
> I want to write code that searches for an error number, and then
> prints everything in between the two error number labels.  So if
> I type something like:
> 
> >lzget -error=12
> 
> then the script should print:
> 
> >Couldn't set the transfer mode to binary.

  #!/usr/bin/perl
  #
  # [ untested ]
  #

  die "Usage: $0 ERROR\n" unless @ARGV;

  my $num = shift;
  my $rx  = qr/^#error$num$/;

  while (<>) {
      my $range = /$rx/ .. /$rx/;

      next unless $range;            # outside group
      next if $range == 1;           # first line
      last if $range =~ /E0/;        # last line

      s/^#\s+//;
      print;
  }

-- 
Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to