1833832 Members
2796 Online
110063 Solutions
New Discussion

Unix date command in awk

 
SOLVED
Go to solution
Donald Dawson
Frequent Advisor

Unix date command in awk

I understand system commands can be executed and stored in a variable within awk. Unfortunately, when using any date commands, the date value does not change. Please see the example - any ideas why?

onstat -g ses 30 -r 10 |\
awk '/Current SQL/,/Last parsed/ {
if ($1 == "Current") {
"date" | getline d
print d
} else if ($1 != "Last") print $0
}
'
Thu Sep 25 13:56:22 CDT 2003
SELECT * FROM udfdef,udf WHERE udfdef.udtype= ? AND udfname= ?
AND udfdef.udfindex=udf.udfindex AND udf.udtype= ? AND udf.udjoin= ?
AND udf.udsort=1

Thu Sep 25 13:56:22 CDT 2003
SELECT * FROM pfun WHERE pname= ? AND pformat IS NULL
1 REPLY 1
Scot Bean
Honored Contributor
Solution

Re: Unix date command in awk

You need to close your "date" pipe before using it again in the loop:


close("date")



Only one pipe open at a time. You were getting the same date from the same pipe each time. Does not work like shell script.