Operating System - HP-UX
1837004 Members
1829 Online
110111 Solutions
New Discussion

large number displayed as exponential form

 
SOLVED
Go to solution
Kenneth_18
Frequent Advisor

large number displayed as exponential form

Hi,

I'm trying to count the number of lines in a very huge log file about 1.5 million lines in our HP-UX server which has a about 1.5GB ram. I'm using an awk script below:

#awk 'END {print MR}' logfile. The output is the following 1.50363e+06.

How can I set it so that it would not be outputted as such since I need the exact count.

I've done the same script in a linux desktop and it gives me the exact number which is 1,503,629. However, my linux box has a low memory (256 MB) so I cant keep on using it on logfiles with more than 500MB in size as it will take a very long time.
2 REPLIES 2
Sridhar Bhaskarla
Honored Contributor
Solution

Re: large number displayed as exponential form

Hi,

Use printf statement in your awk.

awk 'END{printf "%.f", MR}'



-Sri

You may be disappointed if you fail, but you are doomed if you don't try
Mike Stroyan
Honored Contributor

Re: large number displayed as exponential form

You can also change the format for a plain print statement. The OFMT variable is used by default-

awk 'END {OFMT="*.22g";print NR}' logfile

Of course, you can get the answer much faster using a more specialized command.

% time awk 'END {OFMT="%.22g";print NR}' logfile
1382156

real 0m8.51s
user 0m8.40s
sys 0m0.11s

% time (wc -l logfile | awk '{print $1}')
1382156

real 0m0.73s
user 0m0.42s
sys 0m0.32s