Reputation: 43
I am facing a problem in Cygwin when I execute the below command in Unix Environment then output is coming different as compare to Cygwin
echo 0000036703386618|awk '{$1=$1+0; print $1}'
Output is in Unix
36703386618
Output is in Cygwin
3.67034e+10
Please assist
Upvotes: 0
Views: 86
Reputation: 94604
Awk doesn't actually store the value as an integer, it stores it as a floating point value, so you're probably getting an output error due to the outputter being unable to display a > 32bit value in a non-scientific format (this is just a guess, but it's what happens when we switch to mawk)
natsu ~> echo 0000036703386618|mawk '{$1=$1+0; print $1}'
3.67034e+10
natsu ~> echo 0000036703386618|gawk '{$1=$1+0; print $1}'
36703386618
bear in mind that because of the internal representation of the value, it will produce some undesirable results:
natsu ~> echo 0000036703386618000000000|gawk '{$1=$1+0; print $1}'
36703386617999998976
Once you're dealing with 64bit numbers, though, you should start using something that handles them properly - e.g. bc
natsu ~> bc <<<"0000036703386618000000000 + 0"
36703386618000000000
... the prior example uses the <<<
bash redirect to take stdin from a string/variable instead of having to do a echo "$var" |
Upvotes: 2