I have various numbers that I'm printing out from a statistical summary script. I'd like it to stop using exponential format. Of course, I can use printf with 'd' and 'f' and various parameters to specify a format, but then it has other undesirable effects, like tacking on extra 0's or truncating values. I'd just like it to print the number without using exponential format, and preserving decimal values but not prepending or appending zeroes.
Sorry... that's a kind of vague question. It comes from trying to wrap my brain around printf; it's not really that tough, but it's very new to me and the exercises I'm giving myself are not quite working as I thought.
Here's my script, for reference...
#! /usr/bin/awk -f
## Output in a nice format:
## count,min,max,sum,mean,stddev,pop_stddev
BEGIN {
OFS = ","
}
# Main section...
# The count is simply NR
{
if ( min !~ "[0-9]" )
{
min = $1
}
if ( $1 < min )
{
min = $1
}
if ( $1 >= max )
{
max = $1
}
sum += $1
delta = $1 - mean
mean += delta / NR
meansqr += delta * ( $1 - mean )
}
END {
std_dev = sqrt( meansqr / NR )
if ( NR > 1 )
{
pstd_dev = sqrt( meansqr / ( NR - 1 ) )
}
else
{
pstd_dev = 0
}
# printf("%d,%d,%d,%d,%d,%d,%d\n",FNR,min,max,sum,mean,std_dev,pstd_dev)
print FNR,min,max,sum,mean,std_dev,pstd_dev
}
And a few lines of output from various instances of using it:
15,2048,12582912,27329844,1.82199e+06,3.47817e+06,3.60025e+06
2,16384,20480,36864,18432,2048,2896.31
1,12288,12288,12288,12288,0,0
11,12288,116391936,184591770,1.67811e+07,3.27268e+07,3.43241e+07