On Monday, February 27, 2023 at 3:08:47 AM UTC-5, Janis Papanagnou wrote:
On 27.02.2023 08:26, Kenny McCormack wrote:
In article <tth6o8$2o3p$[email protected]>,
jeorge <[email protected]d> wrote:
[...]
Given what I think I understand about your task(s), it'd probably be better
to just write it as a (bash) shell script.
Yeah, that's what I also thought when I upthread asked for a rationale
of using awk as technical frame for a shell task. - I read the OP's statements as if he's just experimenting with awk.
Modern bash has most of what
you need to do real scripting. About the only thing missing is decimal (aka, floating point) arithmetic, and this can usually be easily done via a
"bc" co-process (or, in a pinch, a call to awk).
Note that the shell features are minimalistic here, so any standard
POSIX shell will do, and then you can use ksh (instead of bash) to
also do the FP arithmetics in shell and avoid clumsy and inefficient workaround with external processes.
Janis
[…]
if you only care for unix epochs numerically, and don't mind constantly resetting your rand() seed, then here's one way to extract it within just about any awk, even those without systime() :
for _____ in 1; do (____='($!NF = sprintf("%.0s%.*f", srand(), ___ = ( (__=srand()) ~ "#" ) * 6, substr(__, ++___)))^_'; for ___ in 'gawk -P' 'gawk -c' 'gawk -M' 'gawk -l time' 'gawk -be' nawk mawk1 mawk2 ; do echo " $___ ::\n\n$( (time ( jot 1000 | $(
printf '%s' "$___" ) "$____" ) | gcat -b ) | gtail -n 3 )\n"; done; gawk -p- "$____" <<<'' ) done | gsed -zE 's/\t/ /g; s/ /. /g'
( jot 1000 | $(printf '%s' "$___" ) "$____"; ) 0.01s user 0.00s system 88% cpu 0.018 total
gcat -b 0.00s user 0.00s system 7% cpu 0.018 total
( jot 1000 | $(printf '%s' "$___" ) "$____"; ) 0.01s user 0.00s system 90% cpu 0.017 total
gcat -b 0.00s user 0.00s system 9% cpu 0.016 total
( jot 1000 | $(printf '%s' "$___" ) "$____"; ) 0.48s user 0.01s system 99% cpu 0.484 total
gcat -b 0.00s user 0.00s system 0% cpu 0.484 total
gawk: warning: The time extension is obsolete. Use the timex extension from gawkextlib instead.
( jot 1000 | $(printf '%s' "$___" ) "$____"; ) 0.01s user 0.00s system 89% cpu 0.017 total
gcat -b 0.00s user 0.00s system 8% cpu 0.017 total
( jot 1000 | $(printf '%s' "$___" ) "$____"; ) 0.01s user 0.00s system 91% cpu 0.016 total
gcat -b 0.00s user 0.00s system 9% cpu 0.016 total
( jot 1000 | $(printf '%s' "$___" ) "$____"; ) 0.00s user 0.00s system 102% cpu 0.007 total
gcat -b 0.00s user 0.00s system 20% cpu 0.007 total
( jot 1000 | $(printf '%s' "$___" ) "$____"; ) 0.00s user 0.00s system 106% cpu 0.004 total
gcat -b 0.00s user 0.00s system 41% cpu 0.004 total
( jot 1000 | $(printf '%s' "$___" ) "$____"; ) 0.00s user 0.00s system 103% cpu 0.006 total
gcat -b 0.00s user 0.00s system 22% cpu 0.006 total
gawk -P ::
. 998. . 1678303956
. 999. . 1678303956
. 1000. . 1678303956
gawk -c ::
. 998. . 1678303956
. 999. . 1678303956
. 1000. . 1678303956
gawk -M ::
. 998. . 1678303956
. 999. . 1678303956
. 1000. . 1678303956
gawk -l time ::
. 998. . 1678303956
. 999. . 1678303956
. 1000. . 1678303956
gawk -be ::
. 998. . 1678303956
. 999. . 1678303956
. 1000. . 1678303956
nawk ::
. 998. . 1678303956
. 999. . 1678303956
. 1000. . 1678303956
mawk1 ::
. 998. . 1678303956
. 999. . 1678303956
. 1000. . 1678303956
mawk2 ::
. 998. . 1678303956.854256
. 999. . 1678303956.854260
. 1000. . 1678303956.854263
1678303956
. . # gawk profile, created Wed Mar. 8 14:32:36 2023
. . # Rule(s)
. . 1. ($! NF = sprintf("%.0s%.*f", srand(), ___ = ((__ = srand()) ~ "#") * 6, substr(__, ++___))) ^ _ { # 1
. . 1. . . print
. . }
** srand() needs to be called twice since it only returns the previous seed
** mawk2 uniquely provides micro-second precision for platforms that support it. Floor it or round it to align with the others.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)