Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #9780

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

From Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups comp.lang.awk
Subject Re: A feature I'd like to see in GAWK...
Date 2024-07-16 17:10 +0000
Organization A noiseless patient Spider
Message-ID <20240716100108.429@kylheku.com> (permalink)
References <v73pof$3gdp5$2@news.xmission.com>

Show all headers | View raw


On 2024-07-15, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> --- 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.

TXR Lisp Awk macro:

1> (awk (:inputs (open-command "df -l")) (#/tmpfs/ (prn [f 5])))
/run
/dev/shm
/run/lock
/sys/fs/cgroup
/run/user/122
/run/user/500
nil

:inputs arguments can be files, lists of strings, input streams.

2> (awk (:inputs '("alpha beta" "gamma delta")) (t (prn [f 0])))
alpha
gamma
nil
3> (awk (:inputs "/etc/hostname") (t (prn [f 0])))
sun-go
nil

nil is the return value of the awk expression. You can control that.
The awk construct establishes a hidden block named awk around
your code.

E.g. return the first tmpfs path from "df -l":

4> (awk (:inputs (open-command "df -l"))
        (#/tmpfs/ (return-from awk [f 5])))
"/run"

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Back to comp.lang.awk | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

A feature I'd like to see in GAWK... gazelle@shell.xmission.com (Kenny McCormack) - 2024-07-15 18:28 +0000
  Re: A feature I'd like to see in GAWK... Mack The Knife <mack@the-knife.org> - 2024-07-16 14:29 +0000
    Which, as noted, is ugly and not AWK (Was: A feature I'd like to see in GAWK...) gazelle@shell.xmission.com (Kenny McCormack) - 2024-07-16 16:25 +0000
  Re: A feature I'd like to see in GAWK... Kaz Kylheku <643-408-1753@kylheku.com> - 2024-07-16 17:10 +0000
  Re: A feature I'd like to see in GAWK... "Arti F. Idiot" <addr@is.invalid> - 2024-07-16 14:05 -0600
    Re: A feature I'd like to see in GAWK... gazelle@shell.xmission.com (Kenny McCormack) - 2024-07-17 12:23 +0000
  Re: A feature I'd like to see in GAWK... Jeremy Brubaker <jbrubake.362@orionarts.invalid> - 2024-07-19 14:26 +0000

csiph-web