Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strftime when not using gawk 3

Status
Not open for further replies.

pigna

Programmer
Nov 9, 2006
10
NL
I have this command running on Linux :

vmstat 30|awk '{now=strftime("%Y%m%d %T"); print now $0}'

But on Solaris I obviously don't have strftime. Any options or custom function to create same behaviour...
 
Thanks for your quick reply Feherke!

As far as I can see the difference between the two is that the original version updates the timestamp per record. The 2nd has a fixed timestamp...
 
And what about this ?
vmstat 30|awk 'BEGIN{cmd="date +\"%Y%m%d %T\""}{cmd | getline now;print now $0;close(cmd)}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That did it super !! Thank you ...
 
Damn I was too excited yesterday when experimenting on my test system. It seems the prod system has the very basic awk and that one does not alow for "command" | getline syntax.

(seems only supported by NAWK and GAWK).

Guess that means: not possible in this version?
 
Hi

As far as I know, that [highlight #eee]"command" | getline[/highlight] is standard [tt]awk[/tt]. [tt]mawk[/tt] can do it also.

At this point I would try an off-topic solution :
Code:
vmstat 30 | perl -pe '@t=localtime;printf"%d%02d%02d %02d:%02d:%02d",$t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$t[0]'

Feherke.
 
Are your test and production systems the same versions of Solaris? Does which awk point to the same location on both systems?

Try using nawk or /usr/xpg4/bin/awk instead. It does seem that the extremely old /usr/bin/awk on Solaris doesn't support command | getline.

Annihilannic.
 
My mistake. I didn't know the Solaris box had multiple versions of awk installed. Using nawk made my last question obsolete.

Thanks all for your quick support!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top