cat 6months.pl
#!/usr/bin/env perl
use Text::CSV;
use DateTime;
use DateTime::Format::Strptime;
use autodie qw/ open close /;
my $csv = Text::CSV->new({binary => 1, quote_space => 0});
my $dateparser = DateTime::Format::Strptime->new(pattern => "%d/%m/%Y %T", time_zone => "local");
for my $file (@ARGV) {
open my $fh, '<', $file;
while (my $row = $csv->getline($fh)) {
my $datestr = shift @$row;
my $date = $dateparser->parse_datetime($datestr)->truncate(to => month);
my $end = $date->clone->add(months => 6);
while ($date <= $end) {
$csv->say(STDOUT, [$dateparser->format_datetime($date), @$row]);
$date = $date->add(days => 1);
}
}
close $fh;
}
Executando:
perl 6months.pl data.csv
01/01/2017 00:00:00,sampledata,1234,sample,123455,67546464
02/01/2017 00:00:00,sampledata,1234,sample,123455,67546464
...
30/06/2017 00:00:00,sampledata,1234,sample,123455,67546464
01/07/2017 00:00:00,sampledata,1234,sample,123455,67546464
Só notei isso redefine o tempo para a meia-noite. Se você quiser manter o tempo, faça isso:
my $date = $dateparser->parse_datetime($datestr)->set(day => 1);
# ^^^^^^^^^^^^^