#!/usr/bin/perl
use strict;
use Expect;
my $object = Expect->spawn( "bash" ) or
die "Could not spawn bash shell.\n";
$object->log_stdout(0);
$object->max_accum( 128 * 512 );
my $header = "Test Log Header";
$object->send( "cat test_log.txt\n" );
my ($matched_pattern_position, $error,
$successfully_matching_string, $before_match,
$after_match) =$object->expect( 5 , -re => $header );
if( $error ne undef ) {
die "Could not find header.\n";
}
my @rows = split /^/ , $after_match;
printf "Found %d lines after match in file.\n", scalar( @rows );
####
Test Log Header
040702003113 21% 1175 1859 8239 8744 2221 0 0 4 100% 7% T 6%
040702003113 21% 1175 1859 8239 8744 2221 0 0 4 100% 7% T 6%
040702003113 21% 1175 1859 8239 8744 2221 0 0 4 100% 7% T 6%
040702003113 21% 1175 1859 8239 8744 2221 0 0 4 100% 7% T 6%
040702003113 21% 1175 1859 8239 8744 2221 0 0 4 100% 7% T 6%
...for 160 lines...
####
Output of "wc test_log.txt":
161 2243 9776 test_log.txt
Ouput of "test.pl":
Found 34 lines after match in file.