Retrieve the time into an AWK variable
blux
Posted messages
2045
Registration date
Status
Moderator
Last intervention
-
blux Posted messages 2045 Registration date Status Moderator Last intervention -
blux Posted messages 2045 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
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
-
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é.
-
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)-
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"
-