Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. cat 6months.pl
  2.  
  3. #!/usr/bin/env perl
  4. use Text::CSV;
  5. use DateTime;
  6. use DateTime::Format::Strptime;
  7. use autodie qw/ open close /;
  8.  
  9. my $csv = Text::CSV->new({binary => 1, quote_space => 0});
  10. my $dateparser = DateTime::Format::Strptime->new(pattern => "%d/%m/%Y %T", time_zone => "local");
  11.  
  12. for my $file (@ARGV) {
  13. open my $fh, '<', $file;
  14. while (my $row = $csv->getline($fh)) {
  15. my $datestr = shift @$row;
  16. my $date = $dateparser->parse_datetime($datestr)->truncate(to => month);
  17. ( my $end = $date->clone )->add(months => 6);
  18. while ($date <= $end) {
  19. $csv->say(STDOUT, [$dateparser->format_datetime($date), @$row]);
  20. $date = $date->add(days => 1);
  21. }
  22. }
  23. close $fh;
  24. }
  25.  
  26. perl 6months.pl data.csv
  27.  
  28. 01/01/2017 00:00:00,sampledata,1234,sample,123455,67546464
  29. 02/01/2017 00:00:00,sampledata,1234,sample,123455,67546464
  30. ...
  31. 30/06/2017 00:00:00,sampledata,1234,sample,123455,67546464
  32. 01/07/2017 00:00:00,sampledata,1234,sample,123455,67546464
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement