Re: A feature I'd like to see in GAWK...

Liste des GroupesRevenir à cl awk 
Sujet : Re: A feature I'd like to see in GAWK...
De : mack (at) *nospam* the-knife.org (Mack The Knife)
Groupes : comp.lang.awk
Date : 16. Jul 2024, 15:29:10
Autres entêtes
Organisation : SunSITE.dk - Supporting Open source
Message-ID : <669683b6$0$713$14726298@news.sunsite.dk>
References : 1
User-Agent : trn 4.0-test77 (Sep 1, 2010)
While this is interesting, it can actually be done very easily from the
shell level, using process substitution:

awk -f foo.awk <(df) <(df)


In article <v73pof$3gdp5$2@news.xmission.com>,
Kenny McCormack <gazelle@shell.xmission.com> wrote:
As we know, AWK in general, and GAWK in particular, has several different
ways of getting data into the program.  In addition to the Automatic Input
Loop (the main feature of AWK), there are several variations of "getline".
>
"getline" can be used with files, or with processes (in 2 different ways!),
or even with network sockets.  But the problem with getline is that using
it breaks the Automatic Input Loop.  You can't use the standard
"pattern/action" paradigm if your input is coming in via "getline".  Yes,
there are workarounds and yes we've all gotten used to it, but it is a
shame.  For one thing, you can write your program as a shell script, and
use the shell to pipe in the data from a process.  But this is ugly.  And
not always sufficient.
>
Now, I have written a GAWK extension to handle this - called "pipeline".
Here is a sample script that uses "pipeline".  Note that the Linux "df"
command has a "-l" option to show you only the local filesystems, but what
I usually want is the non-local ones - that's much more interesting.  The
only way I can figure how to get that is to run "df" twice and compare the
output with and without "-l".  Here is my program (non-local-df):
>
--- Cut Here ---
@load "pipeline"
@include "abort"
# Note: You can ignore the "abort" stuff.  It is part of my ecosystem, but
# probably not part of yours.
BEGIN {
   testAbort(ARGC > 1,"This program takes no args!!!",1)
   pipeline("in","df -l")
   while (ARGC < 3)
ARGV[ARGC++] = "-"
   }
ENDFILE { if (ARGIND == 1) pipeline("in","df") }
ARGIND == 1 { x[$1]; next }
FNR == 1 || !($1 in x)
--- Cut Here ---
>
Needless to say, I'd like to see this sort of functionality built-in.
>
It seems to me that GAWK has been sort of fishing around lately looking for
new worlds to conquer.  Some features have been added lately that seem (to
me anyway) sort of "out of place".  namespaces, MPFR arithmetic (apparently,
now deprecated), persistent memory (nifty idea, though I don't really see
the practicality - and have not gotten around to testing it - i.e.,
compiling up a new enough version to try it).
>
I think something like the above would be more in line with the sort of
things I'd like to see in GAWK.
>
--
Adderall, pseudoephed, teleprompter



Date Sujet#  Auteur
15 Jul 24 * A feature I'd like to see in GAWK...7Kenny McCormack
16 Jul 24 +* Re: A feature I'd like to see in GAWK...2Mack The Knife
16 Jul 24 i`- Which, as noted, is ugly and not AWK (Was: A feature I'd like to see in GAWK...)1Kenny McCormack
16 Jul 24 +- Re: A feature I'd like to see in GAWK...1Kaz Kylheku
16 Jul 24 +* Re: A feature I'd like to see in GAWK...2Arti F. Idiot
17 Jul 24 i`- Re: A feature I'd like to see in GAWK...1Kenny McCormack
19 Jul 24 `- Re: A feature I'd like to see in GAWK...1Jeremy Brubaker

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal