#!/usr/bin/perl use strict; use warnings; # source file directory. my $srcdir = "../source"; # source file name. my $srcfile = $srcdir."/vol.dat"; # Open source file in READ mode. open (READ, "< $srcfile") || die "Can't find the DAT file\n"; ################## Start date time i.e. the first day of the last 30 days, is calculated by this code. my $epochToday1 = time; $epochToday1 = $epochToday1 - 2592000; my ($year1, $month1, $day1) = (localtime($epochToday1))[5,4,3]; $month1++; $year1+=1900; my $startdate = $year1."-".$month1."-".$day1; ######################## ################## End date time i.e. the current day, is calculated by this code. my $epochToday2 = time; my ($year2, $month2, $day2) = (localtime($epochToday2))[5,4,3]; $month2++; $year2+=1900; my $enddate = $year2."-".$month2."-".$day2; ######################## # Destination Directory. my $desdir = "../target"; #destination File name. my $desfile = $desdir."/total_volume_last30days.csv"; #Open target file in Write mode. open (WRITE, "> $desfile") || die "Can't find the CSV file.\n"; # Print the headers for the Report in CSV. my @headers = ("Date",",","Total_Volume"); print WRITE @headers,"\n"; my $printout; #declaration of variable which prints in the Target file. while () { my $start = $startdate; my $end = $enddate; if ( /^$start/ .. /^$end/ ) #range to be checked and written to Target file. { chomp; my (@items) = split (/,/,$_); my $tot = $items[1]+ $items[2]; #sum of incoming an outgoing bytes. $printout .= "$items[0],$tot \n"; #variable which stores the Data to be written in target file. } } print WRITE $printout; #write $printout values to Target file. close READ || die "Couldn't close the DAT file"; #close input file. close WRITE || die "Couldn't close the CSV file"; #close target file. exit 0;