[Toybox] awk (Re: ps down, top to go)

Rob Landley rob at landley.net
Mon May 23 16:18:28 PDT 2016


On 05/23/2016 01:28 PM, enh wrote:
> On Sun, May 22, 2016 at 11:23 AM, Rob Landley <rob at landley.net> wrote:
>> My limiting factor with awk is I need to collect a large corpus of awk
>> test scripts so I know what success looks like.
> 
> (coincidentally i was joking to someone last week that you could
> probably replace awk with a binary that only understood "{ print $2;
> }" and it would be years before anyone would notice. it's been a long
> time since i saw anything else in real life...)

That's all I ever use it for myself. And I'm tempted to just _implement_
that, but... that's probably not "doing it right". (What does "doing it
right" mean here? Sigh.)

Really, there should _be_ a command for this. Hmmm... You could do it
with "cut" if the default field delimiter wasn't (I kid you not) tab.
Huh, I wonder, if I changed that to default shell $IFS would anybody
ever actually NOTICE?

In theory printf has a %1s syntax, but in practice it's pulling from its
argument list (not lines read from stdin) and if you don't consume all
arguments it wraps and repeats strangely. Plus needing to remember to
stick a \n on the end of the line which nobody ever does on the first
attempt.

I could add a -u to xargs to tell it "only use these fields in this
order", and make that a comma separated list. I've got infrastructure to
parse those already. :)

A semi-clean thing to do is add a new "words" command that does it, then
it's either there or it isn't. Hmmm, how does the attached look?

(Long-term, horrible FSF configure scripts do elaborate things with awk,
so I need the full one eventually anyway. But using awk for "print $2"
is silly either way.)

>>> The difference arises from the language itself.  The main sh language
>>> has no expressions and hence no left recursion; it's essentially LL(1)
>>> (except for looking ahead to find the ( in a function def).
>>
>> You can recurse, you can throw stuff on a stack. Not a big deal either way.
>>
>> No man page for ll or LL. When I type "ll" Ubuntu has it as an alias for
>> ls -l (so no prompt for a package to install). And LL says command not
>> found (again, no prompt for a package to install).
> 
> (https://en.wikipedia.org/wiki/LL_grammar)

I've long had a theory there are two types of programmers,
mathematician-based and engineering-based, who approach programming in
fundamentally different ways. I've worked with mathematicians, and I got
a math minor for the same reason an acrophobic person would go skydiving
(I refused to be beaten by it), but I am TOTALLY an engineer. It's
plumbing and clockwork metaphors all the way down around here, and one
of my favorite conference talks was somebody listing the bugs they found
in a project that had been formally proved "correct". :)

I've seen a few programmers who are equally comfortable working in both
modes at once (Fabrice Bellard is the ur-example, and I work for another
one at $DAYJOB, Jeff Dionne). But they're few and far between.

I mention this because the article at that link looks like ivory tower
academic fluff to me. I can drag out the crampons and grind my way
through a closer reading, but I'm 99% certain LL is _not_ an existing
software package or library, it appears to be a way of applying the
International Code of Zoological Nomenclature to programming languages
so academics can sort the papers they write about them in the Journal Of
Open Source Tenure Review.

Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: words.c
Type: text/x-csrc
Size: 1177 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20160523/ec6cae41/attachment-0004.c>


More information about the Toybox mailing list