Retrieve the time into an AWK variable

blux Posted messages 5028 Registration date   Status Moderator Last intervention   -  
blux Posted messages 5028 Registration date   Status Moderator Last intervention   -
Hello,

does anyone know how to retrieve the current time, and more generally any result from an external command inside an AWK script to assign it to a variable?

If so, please enlighten me.

--
A+ Blux
 "The dumb ones, they dare everything. It’s even what identifies them"

2 answers

jipicy Posted messages 40842 Registration date   Status Moderator Last intervention   4 898
 
Hi,
[jp@Mandrake tmpfs]$ echo "Il est très exactement " | awk -v valeur="$(date '+%H:%M:%S')" ' { print $0 valeur } ' Il est très exactement 22:04:33 [jp@Mandrake tmpfs]$
;-))
--
Z'@+...che.
JP : Zen, my Nuggets ! ;-) Le savoir n'est bon que s'il est partagé. 
1
blux Posted messages 5028 Registration date   Status Moderator Last intervention   3 455
 
Yes, I would have preferred not to have it at the invocation but during the procedure... In the end, I’m going to change my stance: a2p... -- A+ Blux "Fools go so far as to dare everything. That’s how you recognize them."
0
jisisv Posted messages 3678 Status Moderator 936
 
Read man awk
Search "Time Functions" "systime"

example:

johand@horus:~$ awk '{ print strftime("%Y/%m/%d-%H:%M:%S",systime()) } '
1
2005/12/09-15:50:27
2
2005/12/09-15:50:28
3
2005/12/09-15:50:30

Regarding external commands, I did not go into depth, but there is a system command (you can retrieve the exit code of the command).
I did not see a trace of popen. But this may vary with awk versions...

Johan
--
Gates gave you the windows.
GNU gave us the whole house. (Alexandrine)
0
blux Posted messages 5028 Registration date   Status Moderator Last intervention   3 455
 
Thank you for your reply, but my awk (AIX 5.2, I didn’t specify that) doesn’t know systime or strftime...

And for the system command, we indeed only get the return code back (you know I had tested it)...

I was thinking more of a trick with indirection, like toto=`system(date)` or toto=$(system(date))
as in shell... but it didn’t work :-(

--
A+ Blux
 "Les cons, ça ose tout. C'est même à ça qu'on les reconnait"
0