awk to output cmd result

I was wondering if it was possible to tell awk to print the output of a command in the print.

 .... | awk '{print $0}'

I would like it to print the date right before $0, so something like (this doesn't work though)

 .... | awk '{print date $0}'
... | awk '{ "date" | getline date; print date " " $0 }'

Querying the date again and again for each line is pretty wasteful, though. Perhaps you want to do it in a BEGIN block, or something like

... | awk -v date="`date`" '{ print date " " $0 }'

Really old classical awk might not have all the required facilities; try nawk or mawk or gawk if your plain awk won't do. On HP-UX in particular, you may find that the xpg4 awk is more modern than the plain /usr/bin/awk. Searching this forum suggests that setting the environment variable UNIX95=1 might get you that.

You have very clueful questions, keep it up! (-:

That last one you posted works, but its static. The output of date never changes. Is there a way to make it dynamically call date every time it prints?

Thanks

Avoiding that was kind of the point. Try to find an awk which is new enough to do the first.

Here is one way of doing what you want:

{
   "date +%T" | getline cur_date; print cur_date, $0
}