Weird AWK behavior while forcing expression to be a number (adding 0) -
I saw a strange behavior by introducing an array in awk
. The index and value were both numbers, so should not be affected by adding 0
. For the sake of understanding, take the following example:
Here is a file I want to use for this demo:
$ cat file 2.60E5-2670161065730303122012098 Invnum987678 2.60E5-2670161065846403042011098 Invnum987912 2.60E5-2670161065916903012012075 Invnum987654 2.60E5-2670161066813503042011075 Invnum987322 2.60E5-2670161066835008092012075 Invnum987323 2.60E5-2670161067040701122012075 Invnum987324 2.60E5-2670161067106602122010074 Invnum987325
index of what I want to do is make a Specify a value from $ 1
and from it $ 2
. I will extract the piece of value of the $ 1
and the $ 2
function from substr
I
$ awk '{ P = substr ($ 1,12) + 0; A [P] = Substitact ($ 2,7) +0; Next} END {For X in A} Print X, A [x]} 'File
Now, ideally the output should have been as follows (This fact should be ignored Associative arrays are output randomly):
161065730303122012098 98767816106584640404242011098 987912161065916903012012075 987654 161066813503042011075 987322 161066835008092012075 987323 161067040701122012075 987324 161067106602122010074 987325
But this output is to me The following was as follows:
161066835008092012544 987323 161065846403042017280 987912161067040701122019328 987324161067106602122018816 9873251610668135 03041994752 987322 161065916903012007936 987654 161065730303122014208 987678 If I remove +0
from the top awk
one liner, the output I hope what is happening, what I want to know, why would this key corrupt?
The above testing was done:
$ awk -version awk version 20070501
Comments
Post a Comment