I'm following @zdim's recursive solution in this question fastest way to sum the file sizes by owner in a directory to get my file sizes summed up by year-month
perl -MFile::Find -E' use POSIX;
$dir = shift // ".";
find( sub {
return if /^\.\.?$/;
my ($mtime, $size) = (stat)[9,7];
my $yearmon = strftime "%Y%m",localtime($mtime);
$rept{$yearmon} += $size ;
}, $dir );
say ("$_ => $rept{$_} bytes") for sort keys %rept
'
It gives results like this.
201701 => 7759 bytes
201702 => 530246 bytes
201703 => 3573094 bytes
201704 => 425827 bytes
201705 => 3637771 bytes
201706 => 2325391018 bytes
201707 => 127005 bytes
201708 => 2303 bytes
201709 => 231465431 bytes
201710 => 273667 bytes
201711 => 6397659 bytes
201712 => 333587 bytes
201802 => 874676 bytes
201803 => 147825681 bytes
201804 => 84971454 bytes
201805 => 3483547 bytes
201806 => 8004797 bytes
201807 => 184676 bytes
201808 => 1967947 bytes
201809 => 1592310 bytes
201810 => 24176 bytes
201811 => 883378 bytes
201812 => 6661592 bytes
201901 => 33979401 bytes
But I need to include year-wise totals after printing all available months in a given year, like below
201710 => 1111 bytes
201711 => 2222 bytes
201712 => 3333 bytes
2017 => 6666 bytes ( summed up )
201803 => 11111 bytes
201809 => 22222 bytes
2018 => 33333 bytes ( summed up )
How do I get that?. There might be blanks in a year-month and it need not end with month 12 for every year.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)