#!/usr/bin/env perl
#
# FILE:
# timechop
#
# FUNCTION:
# Extract a portion of a file given a start and a number of seconds
#
# SAMPLE USAGE:
# cat infile | timechop "Sat Aug 1 13:52:32 1998" 3600 >outfile
#
#

push (@INC, "/usr/local/lib/perl5/5.00501/");
($inky = $0) =~ s/timechop//;
push (@INC, $inky);

require "utils.pl";

$elapse = pop (@ARGV);
$startdate = pop (@ARGV);

printf "# Will start at $startdate and run for $elapse seconds\n";

$starttime = &maketime ($startdate);
$starttime += 331;
$doprt = 0;

while(<>) {
	# grab the date string
	if ($_ =~ /^(=+)(\s+)(.+)/) {
		$datestring = $3;
		$secs = &maketime ($datestring);
		if ($secs > $starttime) { $doprt = 1; }
		if ($secs > $starttime+$elapse) { $doprt = 0; }
	}

	# print the line if printing enabled
	if ($doprt) { print; }

}

