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