Turning off exponential notation in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Turning off exponential notation in awk
# 1  
Old 02-24-2010
Turning off exponential notation in awk

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...

Code:
#! /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:

Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Context for use of [.symbol.] awk notation

Hi Just wondering ... do you have an example of context that would demonstrates how usefull the awk notation can efficiently be used ? Thx :rolleyes: (6 Replies)
Discussion started by: ctsgnb
6 Replies

2. Shell Programming and Scripting

Awk-Exponential Values

Hi Friends, My input Gene1 4.14887050399078e-49 Gene2 5.39999891278828e-10 Gene 2.22108326729483e-11 How do I change the above exponential values to normal values? Thanks (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. Shell Programming and Scripting

[Solved] awk Errors on notation

can someone spot what i'm doing wrong here: awk 'BEGIN{printf("%0.2f", 1 / 2649320) * 100}' i get this error: awk: line 1: syntax error at or near * then i do this and get the answer i'm trying to avoid: awk 'BEGIN{print(1 / 2649320) * 100}' 3.77455e-05 (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

Perl: scientific notation to decimal notation

hello folks, I have few values in a log which are in scientific notation. I am trying to convert into actual decimal format or integer but couldn't able to convert. Values in scientific notation: 1.1662986666666665E-4 2.0946799999999998E-4 3.0741333333333333E-6 5.599999999999999E-7... (2 Replies)
Discussion started by: scriptscript
2 Replies

5. Shell Programming and Scripting

Get rid of awk notation

echo 0.633588 1875 | awk '{print $1 * $2 * 1024}' is there a better way to run the above command? it keeps printing out in notation and i do not want that at all. when i run the above, i get: 1.21649e+06 OS: linux language:bash (1 Reply)
Discussion started by: SkySmart
1 Replies

6. Shell Programming and Scripting

AWK - Avoid exponential value

I'm using the following command, but how can I avoid printing exponential value (highlighted):- awk ' BEGIN { OFS=FS="|" } { if(NF>4) $10=int(((3.77*$11)/100 + $11)); } { print } ' infile CR|20121022|105|GSM|N|SAN|00122|SAN|75082|6.03929e+06|5819880|5794769|25111... (7 Replies)
Discussion started by: Yoda
7 Replies

7. Shell Programming and Scripting

Convert decimal notation to ANSI point code notation

wondering if anyone has any thoughts to convert the below thru a shell script Convert decimal signalling point notation to ANSI point code notation There is a site that does that conversion but i need to implement the solution in a shell script.....Thoughts.... OS: Solaris 9 ... (4 Replies)
Discussion started by: aavam
4 Replies

8. Shell Programming and Scripting

The awk subtraction giving exponential values.Please help resolve it

Hi friends, I have a file list1 which has these 2 columns like 616449 0 434453 1 2151083 0 2226536 0 2132382 0 2136814 0 I have to put the result of col1 -col2 into another file list2 linewise. e.g. It gives the below result if use the below code: awk '{ print $1 - $2 }' list1 >... (2 Replies)
Discussion started by: kunwar
2 Replies

9. Shell Programming and Scripting

Sorting exponential notation

Hi, I just want to sort my file with exponential notation. For example: 1;2;4;s 1;5e-01;4;s 1;1;4;s I used sort -gk2, but it does not sort in the correct way. What's wrong? (15 Replies)
Discussion started by: NilsMueller
15 Replies

10. Shell Programming and Scripting

Conversion of Exponential to numeric in awk- not correct output

Hi All, I have 1 million records file. Using awk, I am counting the number of records. But as the number is huge, after crossing a number, awk is displaying it in exponential format. At the end, I need to verify this count given by awk with expected count. But as it is in exponential format,... (3 Replies)
Discussion started by: ssunda6
3 Replies
Login or Register to Ask a Question