Sujet : Re: A feature I'd like to see in GAWK...
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.awkDate : 16. Jul 2024, 18:10:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240716100108.429@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca