how to extract part of log

Simple perl script below gets as arguments
1. Start pattern (could be regexp in single quotes)
2. End pattern (could be regexp in single quotes)
3. File path

It is opening file and prints  everything between Start and End pattern.

<code>

#!/usr/bin/perl

die “Usage: start_pattern end_pattern file [$#ARGV]” if $#ARGV<2;

open FI, $ARGV[2] || die “Problem with opening file [$ARGV[2]] [$!]\n”;
$START=$ARGV[0];
$END=$ARGV[1];

$in=0;
foreach (<FI>) {
        $in=1 if /$START/;
        print $_ if $in;
        $in=0 if /$END/;

}
close FI;

</code>

Napisz komentarz