onetrueawk / awk

One true awk
Other
1.98k stars 159 forks source link

Maybe at systime() function? #184

Closed sdaoden closed 1 year ago

sdaoden commented 1 year ago

Hello. I did not know about that one, but it came up on gnupg-users, and i responded

` That is easy on Unix:
$ gpg --list-keys --with-colons \
awk -F: -v days=60 \
'BEGIN { from=systime(); to=from+(days*86400)};\

Not that easy ("date +%s" maybe, strftime(3) %s is old).

?2|kent:$ awk 'END{print systime()}' </dev/null

1686316851

?0|kent:$ mawk 'END{print systime()}' </dev/null

1686316853

?0|kent:$ nawk 'END{print systime()}' </dev/null

nawk: calling undefined function systime source line number 1

?2|kent:$ busybox.static awk 'END{print systime()}' </dev/null

1686316860`

The gawk manual says

systime() Return the current time of day as the number of seconds since the Epoch (1970‐01‐01 00:00:00 UTC on POSIX systems).

millert commented 1 year ago

The bsd-features branch has an implementation of systime()

sdaoden commented 1 year ago

Ah! I see, and works. I switched branches. Thank you, Todd Millert!

iamleot commented 1 year ago

Hello! @sdaoden another possible way - that should work on all the AWKs - is:

BEGIN { srand(); t = srand(); print t }

When srand() is called without any argument it will start from the current time of day.

sdaoden commented 1 year ago

Hello!

Leonardo Taccari wrote in @.>: @. another possible way - that should work on all the AWKs - is: ```awk BEGIN { srand(); t = srand(); print t } ```
When srand() is called without any argument it will start from the \
current time of day.

That is actually a brilliant idea! This works back to System V8 awk, and for BSD i am a bit out of ideas, CSRG repo shows nothing before 1994, though gawk came in earlier already. But anyway, for (at least) almost thirty years anywhere!

--steffen Der Kragenbaer, The moon bear, der holt sich munter he cheerfully and one by one einen nach dem anderen runter wa.ks himself off (By Robert Gernhardt) ~~ ..and in spring, hear David Leonard sing..
The black bear, The black bear,
blithely holds his own holds himself at leisure
beating it, up and down tossing over his ups and downs with pleasure
~~
Farewell, dear collar bear
enh-google commented 1 year ago

The bsd-features branch has an implementation of systime()

is there any plan to merge that into the main branch and have them be a compile-time option? asking in the context of keeping Android's copy of awk updated. i'd be interested in having the BSD features for interop, but it's unclear to me how "supported" that branch is long term? (this is the first i remember hearing of it.)

arnoldrobbins commented 1 year ago

The bsd-features branch is supported; the various *BSD distributions use awk from there. It is unlikely that those features will be merged into the main branch, but @plan9 will have to give the final word on that.