[sf-lug] sh, awk, Perl, ... Re: calculating meeting dates ...

Michael Paoli Michael.Paoli at cal.berkeley.edu
Tue Jun 4 05:11:11 PDT 2019


> From: "Rick Moen" <rick at linuxmafia.com>
> Subject: Re: [sf-lug] calculating meeting dates ... Re: SF-LUG  
> meeting notes	for Sunday June 2, 2019
> Date: Mon, 3 Jun 2019 21:35:31 -0700

> Quoting Michael Paoli (Michael.Paoli at cal.berkeley.edu):
>
>> Anyway, ... upcoming meetings ... 'bit 'o Perl code I wrote (I got tired of
>> otherwise figuring out all the various (typically [L]UG) meeting dates.
>
> Perl is almost certainly a better language for such things, as famously
> awk runs out of power in a lot of areas where Perl excels.  It happened
> that the GNU awk date functions were handy and have a good reputation --
> and also that I'm good at awk/sed and totally suck at Perl.  ;->
>
> I can also say with at least a little pride that my sed/awk scripts
> tend to be pretty easy to study and understand, IMO.

Yes, ... shell, e.g. ye olde Bourne sh shell ...
circa 1979 ...
"Very concise reference: UNIX Seventh Edition sh(1) only 6 pages!"
-- http://www.rawbw.com/~mp/unix/sh/
Okay, e.g., current Bash - adds lots 'o bells and whistles
since then, and sometimes big security boo-boos,
but even current minimally POSIX compliant shell, e.g.
dash(1) ...
$ lsb_release -d; man dash | col -b | expand | grep '[^         ]' | wc -l
Description:    Debian GNU/Linux 9.9 (stretch)
1200
$ echo 1200/66 | bc -l
18.18181818181818181818
$
About 19 pages or so.
Perl?  Sure, very capable but ...
1,176 pages for a good reference!:
http://shop.oreilly.com/product/9780596004927.do
And ... awk? ... certainly not all the capabilities of Perl,
not even close, but for some fair useful bits that shell
doesn't do or do so easily ...
$ apropos awk | awk '{if($1 ~ /awk/)print;}'
awk (1)              - pattern scanning and processing language
gawk (1)             - pattern scanning and processing language
igawk (1)            - gawk with include files
mawk (1)             - pattern scanning and text processing language
nawk (1)             - pattern scanning and processing language
$ (cd /usr/bin && ls -iL $(apropos awk | awk '{if(($1 ~ /awk/)&&($1 !=  
"igawk"))print $1;}') | sort -bn)
311354 mawk
311739 awk
311739 gawk
311739 nawk
$ (for a in mawk awk; do echo "$a" $(echo $(man "$a" | col -b | expand  
| grep '[^       ]' | wc -l)/66 | bc -l); done)
mawk 10.10606060606060606060
awk 23.74242424242424242424
$
So ... about 11 pages for mawk (closer to the original awk),
and ... about 24 pages for gawk (which is also awk as
configured/installed on the host where I checked).

So, yep, Perl - pretty dang capable, but there's a lot there to
learn.  Oh, and the numbers I gave regarding Perl - that's not
even counting most of the modules - which provide lots of highly
useful stuff (like date calculations/manipulations, among tons of
other stuff too).  Similar can be said of Python.

So, e.g., within Date::Calc(3pm) (Perl Module), we have:
Days_in_Year Days_in_Month Weeks_in_Year leap_year check_date
check_time check_business_date Day_of_Year Date_to_Days Day_of_Week
Week_Number Week_of_Year Monday_of_Week Nth_Weekday_of_Month_Year
Standard_to_Business Business_to_Standard Delta_Days Delta_DHMS
Delta_YMD Delta_YMDHMS N_Delta_YMD N_Delta_YMDHMS Normalize_DHMS
Add_Delta_Days Add_Delta_DHMS Add_Delta_YM Add_Delta_YMD
Add_Delta_YMDHMS Add_N_Delta_YMD Add_N_Delta_YMDHMS System_Clock Today
Now Today_and_Now This_Year Gmtime Localtime Mktime Timezone
Date_to_Time Time_to_Date Easter_Sunday Decode_Month Decode_Day_of_Week
Decode_Language Decode_Date_EU Decode_Date_US Fixed_Window
Moving_Window Compress Uncompress check_compressed Compressed_to_Text
Date_to_Text Date_to_Text_Long English_Ordinal Calendar Month_to_Text
Day_of_Week_to_Text Day_of_Week_Abbreviation Language_to_Text Language
Languages Decode_Date_EU2 Decode_Date_US2 Parse_Date ISO_LC ISO_UC




More information about the sf-lug mailing list