3 ms·
Under the heavily populated category of Solutions That Aren't, here's my approach. ^_^ Use ncal because it provides the week numbers and can start weeks on Mon
by heresie-dabord 5y ago
Under the heavily populated category of Solutions That Aren't, here's my approach. ^_^
Use ncal because it provides the week numbers and can start weeks on Monday (personal preference). Pipe to sed, fold, and then to Perl. (Perl is awesome.)
ncal -w -3 -y -b -h -M | sed 's/ /*/g' | fold -w 27 |
tail -n 99 | perl -w -e 'use strict;
my (@g1,@g2,@g3,@aAccum)=((),(),(),()); my $tog=1;
sub clearQ{ (@g1,@g2,@g3)=((),(),());}
sub doAccum{ @aAccum=(@g1,@g2,@g3); clearQ();
print @aAccum; @aAccum=(); }
for my $wk(<>){
my $LN=$wk; chomp($LN);
if( length($LN)==0 ){ doAccum(); next;}
if($tog==1){push @g1,$wk;}
elsif($tog==2){push @g2,$wk;}
elsif($tog==3){push @g3,$wk;} $tog++;
if($tog>3){ $tog=1;}
}
doAccum();'
- 1vuio0pswjnm7 5y ago"Use ncal because it provides week numbers and can start weeks on Monday (personal preference)." Use the cal that is in util-linux: https://www.kernel.org/pub/linux/utils/util-linux/ https://www.kernel.org/pub/linux/utils/util-linux/ cal -m starts weeks on Monday. cal -w displays week numbers. Personal preference is not to install Perl unless needed, e.g., for compiling OpenSSL. Takes up precious space that can be used for other things.
- heresie-dabord 5y agoIn *buntu 20.04, I have cal and ncal. But yes, any common cal utility that generates week numbers is a better solution than cal -y | ... | wc -l. I understand your preference for a lean file system. In this challenge, I needed more than awk (because of arrays) and wanted an explicit solution that works regardless of calendar language.