Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.awk Subject: Re: A feature I'd like to see in GAWK... Date: Tue, 16 Jul 2024 17:10:25 -0000 (UTC) Organization: A noiseless patient Spider Lines: 54 Message-ID: <20240716100108.429@kylheku.com> References: Injection-Date: Tue, 16 Jul 2024 19:10:25 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ce357bc76c882e1ee63521671b53ee1f"; logging-data="1437239"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ebQs6DwY8IigX5RssKvjAr71ld7D5UpA=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:MeGZbyFrbCe/I5t2Rzoz48CuaEM= Xref: csiph.com comp.lang.awk:9780 On 2024-07-15, Kenny McCormack 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