Print a very large number in unix

3.3k views Asked by At

I have a unusual problem which I have no idea how to solve.
I have a awk script to calculate sum of different elements but at the end i have a very large number as result ( and that is normal) but my concern is how the number is displayed 1.84745e+09 .

Any idea to get the "correct" form like i mean 182739293747493274 for example

for example this is the awk code i'm using

awk -F, 'FNR==1 {header=$0; next} {a[$1]+=$6+$14} END {for (i in a) {print i, a[i]; tot+=a[i]} print "TOTAL", tot}' CAS01.txt CAS02.txt CAS03.txt 

and here the output i have

20140201 -5.04108e+08 20140202 -5.74709e+08 20140228 -7.68633e+08 TOTAL -1.84745e+09

My concern is that i want the output number to be fully displayed not in exposant format

2

There are 2 answers

0
tripleee On

GNU Awk has the extension -M which provides for arbitrary-precision integer arithmetic.

If you can't use GNU Awk, and your Awk does not have a similar extension, you will have to switch to a tool which does (bc comes to mind, or try Perl; there is a tool a2p in the Perl distribution to translate Awk scripts to Perl code).

0
Arjun Mathew Dan On

You can use printf instead of print.

Example:

sdlcb@ubuntu:~/AMD_C$ echo  12.3456 | awk '{printf ("%2.4e\n", $1)}'
1.2346e+01
sdlcb@ubuntu:~/AMD_C$ echo  12.3456 | awk '{printf ("%2.4f\n", $1)}'
12.3456