Code:
$
$
$ cat input
1274706110,a
1274706254,b
1274706331,c
1274706287,d
1274706263,e
1274706358,f
1274706284,g
1274706366,h
1274706102,i
1274706314,j
1274706177,k
1274706280,l
1274706037,m
1274706342,n
1274706210,o
1274706263,p
1274706249,q
1274706255,r
1274706126,s
1274706002,t
1274706369,u
1274706093,v
1274706354,w
1274706110,x
1274706162,y
1274706280,z
$
$ cat -n bucket_divide.pl
1 #perl -w
2 use Time::Local;
3 $start = $ARGV[0];
4 $interval = $ARGV[1];
5 ($mon,$day,$year,$hr,$min) = split/[\/ :]/,$start;
6 $stime = timelocal(0,$min,$hr,$day,$mon-1,$year);
7 $file="input";
8 open(F, $file) or die "Can't open $file: $!";
9 while (<F>) {
10 chomp;
11 ($sec,$item) = split/,/;
12 $indx = int ($sec-$stime)/$interval;
13 $bucket[$indx] .= ",$item";
14 }
15 close(F) or die "Can't close $file: $!";
16 for($i=0; $i<=$#bucket; $i++){
17 $from = scalar localtime($stime+($i*$interval));
18 $to = scalar localtime($stime+(($i+1)*$interval)-1);
19 printf("From: %-25s To: %-25s => %-s\n",$from,$to,substr($bucket[$i],1));
20 }
$
$
$ perl bucket_divide.pl "5/24/2010 9:00" 30
From: Mon May 24 09:00:00 2010 To: Mon May 24 09:00:29 2010 => t
From: Mon May 24 09:00:30 2010 To: Mon May 24 09:00:59 2010 => m
From: Mon May 24 09:01:00 2010 To: Mon May 24 09:01:29 2010 =>
From: Mon May 24 09:01:30 2010 To: Mon May 24 09:01:59 2010 => a,i,v,x
From: Mon May 24 09:02:00 2010 To: Mon May 24 09:02:29 2010 => s
From: Mon May 24 09:02:30 2010 To: Mon May 24 09:02:59 2010 => k,y
From: Mon May 24 09:03:00 2010 To: Mon May 24 09:03:29 2010 =>
From: Mon May 24 09:03:30 2010 To: Mon May 24 09:03:59 2010 => o
From: Mon May 24 09:04:00 2010 To: Mon May 24 09:04:29 2010 => b,e,p,q,r
From: Mon May 24 09:04:30 2010 To: Mon May 24 09:04:59 2010 => d,g,l,z
From: Mon May 24 09:05:00 2010 To: Mon May 24 09:05:29 2010 => j
From: Mon May 24 09:05:30 2010 To: Mon May 24 09:05:59 2010 => c,f,n,w
From: Mon May 24 09:06:00 2010 To: Mon May 24 09:06:29 2010 => h,u
$
$
$ perl bucket_divide.pl "5/24/2010 9:00" 40
From: Mon May 24 09:00:00 2010 To: Mon May 24 09:00:39 2010 => m,t
From: Mon May 24 09:00:40 2010 To: Mon May 24 09:01:19 2010 =>
From: Mon May 24 09:01:20 2010 To: Mon May 24 09:01:59 2010 => a,i,v,x
From: Mon May 24 09:02:00 2010 To: Mon May 24 09:02:39 2010 => s
From: Mon May 24 09:02:40 2010 To: Mon May 24 09:03:19 2010 => k,y
From: Mon May 24 09:03:20 2010 To: Mon May 24 09:03:59 2010 => o
From: Mon May 24 09:04:00 2010 To: Mon May 24 09:04:39 2010 => b,e,p,q,r
From: Mon May 24 09:04:40 2010 To: Mon May 24 09:05:19 2010 => d,g,j,l,z
From: Mon May 24 09:05:20 2010 To: Mon May 24 09:05:59 2010 => c,f,n,w
From: Mon May 24 09:06:00 2010 To: Mon May 24 09:06:39 2010 => h,u
$
$
$