On 05/23/2016 01:28 PM, enh wrote: > On Sun, May 22, 2016 at 11:23 AM, Rob Landley <r...@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
/* words.c - Show numbered words from input lines, in order. * * Copyright 2016 Rob Landley <r...@landley.net> * * No standard USE_WORDS(NEWTOY(words, "d:", TOYFLAG_USR|TOYFLAG_BIN)) config WORDS bool "words" default y help usage: words [-d DELIM] ARG... Show numbered words from input lines, in order. For example, "echo one two three four five | words 3 2 4" would output "three two four". -d Use DELIM instead of space between output words */ #define FOR_words #include "toys.h" GLOBALS( char *d; ) void words_main(void) { char *line = 0, **words = (void *)toybuf; ssize_t len; size_t size = 0; while (0 < (len = getline(&line, &size, stdin))) { char *s = line; unsigned i = 0, j; // Find word boundaries in line for (;;) { if (i >= sizeof(toybuf)/sizeof(void *)) break; while (isspace(*s)) s++; words[i++] = s; while (*s && !isspace(*s)) s++; if (!*s) break; *s++ = 0; } for (len = 0; len<toys.optc; len++) { if (len) printf("%s", TT.d ? TT.d : " "); if(i>(j = atolx(toys.optargs[len])-1)) printf("%s", words[j]); } xputc('\n'); } }
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net