#!/usr/bin/perl
# Use: script.pl YYYY-MM-DD file1 file2 ...
use Time::Local;
use POSIX qw(mktime strftime);
# arg 1 must be YYYY-MM-DD
my ($y, $mon, $d)=split("-", shift);
$mon--; # perl counts months 0-11
my $start=timelocal(0,0,0,$d,$mon,$y);
print "y=$y, mon=$mon, d=$d\n";
while($arg=shift)
{
$fname=sprintf("A%s-%s.csv\n",
strftime("%Y%m%d.%H%M",localtime($start)),
strftime("%Y%m%d.%H%M", localtime($start+(15*60))));
system("echo mv ${arg} ${fname}");
$start += ((15*60));
}
exit 0;
---------- Post updated at 11:50 AM ---------- Previous update was at 11:15 AM ----------
This may do it. It reads the file by itself and prints rows into different files as appropriate.
#!/usr/bin/perl
use Time::Local;
use POSIX qw(mktime strftime);
my $start=0, $end=0, $FMT="%Y%m%d.%H%M";
while($line=<STDIN>)
{
($mdy, $hms, $rest)=split(" ", $line);
($m, $d, $y)=split("/", $mdy);
($hour, $min, $sec)=split(":", $hms);
$ldate=timelocal($sec, $min, $hour, $d, $m-1,$y);
$min=$min-($min%15); # chunks of 15 minutes
if($ldate >= $end)
{
$start=timelocal($sec,$min,$hour,$d,$m-1,$y);
$end=$start + (15*60);
$fname=sprintf("%s-%s.csv",
strftime("$FMT", localtime($start)),
strftime("$FMT", localtime($end)));
FILE && close(FILE);
open(FILE, ">$fname");
}
print FILE "$line";
}
FILE && close(FILE);
exit 0;
Assumes the row begins with M/D/Y H:M:S ...
It'll take the file name from the row data and nothing else.
Use it like ./script.pl < hugefile
It may not be the fastest thing in the universe.