2 ms·
The TXR Lisp dialect provides an awk macro that implements a language closely resembling Awk in its structure and semantics. For example, write the third field
by kazinator 10y ago
The TXR Lisp dialect provides an awk macro that implements a language closely resembling Awk in its structure and semantics.
For example, write the third field of every record (if the field exists) into `file.{recnum}`:
(awk ([f 2] (-> `file.@nr` (prn [f 2]))))
The manual contains a translation of all of the Awk examples from the POSIX standard:
http://www.nongnu.org/txr/txr-manpage.html#N-03D16283 http://www.nongnu.org/txr/txr-manpage.html#N-03D16283
The (-> name form ...) syntax above is scoped to the surrounding awk macro. Like in Awk, the redirection is identified by string. If multiple such expressions appear with the same name, they denote the same stream (within the lexical scope of the awk macro instance to which they belong). These are implicitly kept in a hash table. When the macro terminates (normally or via non-local jump like an exception), these streams are all closed.