Selecting A Section of A File Based On the Time Within It

Hi,

I have a file formated like this:

John      7.22    2010-01-25_17:01:36
George   8.22    2010-01-25_17:02:36
Bob        9.62    2010-01-25_17:04:36
Jane       10.11  2010-01-25_17:05:36
Emma      4.52   2010-01-25_17:01:36

What I want to do is cut out only the entries that have been made in the last fifteen minutes. I had this:

###Finding Current Time
time_now=$(perl -e 'use POSIX qw(strftime);
use Time::Local;
$back_time = (time() - (1*0));
$title_date = strftime("%Y-%m-%d_%H:%M", localtime($back_time));
print $title_date;')

###Finding Time 15 Mins Ago
time_minus_fifteen=$(perl -e 'use POSIX qw(strftime);
use Time::Local;
$back_time = (time() - (1*900));
$title_date = strftime("%Y-%m-%d_%H:%M", localtime($back_time));
print $title_date;')

####Selecting 15 min section of file
awk "/$time_minus_fifteen/,/$time_now/" my_file > fifteen_min_file

This worked nicely until there were no transactions in a particular minute the awk bit was looking for e.g. if it was

awk "/2010-01-25_16:51/,/2010-01-25_17:07/" my_file > fifteen_min_file

and there were no entries made with the timestamp 16:51 then the awk part of the script fails.

Can anybody think of a better way to do this? Is there any function that allows you to query a timestamp. For example in SQL you could do something like time between 16:50:00 and 17:05:00. Is there something like this in awk, ksh or perl?

Any help appreciated!

Cheers

use POSIX qw/strftime/;
use Date::Calc qw(Delta_YMDHMS);

my $curr_time = strftime('%Y-%m-%d_%H:%M:%S',localtime);

while(<>){
        chomp;
        my ($name,$val,$date) = split("\t");
        print "$name\t$val\t$date\n" if (get_diff_in_dates($date,$curr_time));
}


sub get_diff_in_dates {
        my ($date1,$date2) = @_;
        my ($ymd1,$hms1) = split("_",$date1);
        my ($ymd2,$hms2) = split("_",$date2);
        my ($diff_year,$diff_mon,$diff_day,$diff_hr,$diff_min,$diff_sec) = Delta_YMDHMS(split("-",$ymd1),split(":",$hms1),split("-",$ymd2),split(":",$hms2));
        ($diff_min <= 15) ? return 1 : return 0;
}

HTH,
PL

if you have control of the log file
i would include the unix epoch time as a field, then it would be trivial.