Operating System - HP-UX
1819941 Members
3576 Online
109607 Solutions
New Discussion юеВ

why awk gives output as exponential format output

 
moonzh
Occasional Advisor

why awk gives output as exponential format output

I wrote one shell script to get swap size, as below

echo "SWAPSIZE="`/usr/sbin/swapinfo -d | awk 'BEGIN { s=0 } { s=s+$2 } END { p
rint s }'`

In my HP-UX V11.00, it displays result as integer SWAPSIZE=786432.

But at customer's system, the output is exponential format as SWAPSIZE=1.04858e+06

I do not know why? I do want the output is integer. Can anybody help me?
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: why awk gives output as exponential format output

change your awk print to a printf ("%d\n",s)


If it ain't broke, I can fix that.
Peter Nikitka
Honored Contributor

Re: why awk gives output as exponential format output

Use 'printf' instead of 'print', so you can pass a format statement:
/usr/sbin/swapinfo -d | awk 'BEGIN { s=0 }
{s+=$2}
END {printf ("SWAPSIZE=%d\n", s)}'
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
moonzh
Occasional Advisor

Re: why awk gives output as exponential format output

Thx Peter & Clay! You guys solved my problem.