Unexpected value calculated using awk

I have a text file called test.txt containing several lines with fields separated by semicolons. I am trying to accept the value field3> cut everything except the numbers in the field> compare it with the value of field 3 on the previous line> if the value is unique, redirect the value of field 3 and the difference between it and the last value for the file named "differ.txt".

so far I have the following code:

awk -F';' '
BEGIN{d=0} {gsub(/^.*=/,"",$3); 
if(d>0 && $3-d>0){print $3,$3-d} d=$3}
' test.txt > differences.txt

This works fine when I try to run in the following text:

field1=xxx;field2=xxx;field3=111222222;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222222;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222333;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222444;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222555;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222555;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222777;field4=xxx;field5=xxx
field1=xxx;field2=xxx;field3=111222888;field4=xxx;field5=xxx

as expected:

111222333 111
111222444 111
111222555 111
111222777 222
111222888 111

however, when I try to run the following text, I get completely different unexpected numbers - I'm not sure if this is due to an increase in the length of the field or something like that.

Test:

test=none;test=20170606;test=1111111111111111111;
test=none;test=20170606;test=2222222222222222222;
test=none;test=20170606;test=3333333333333333333;
test=none;test=20170606;test=4444444444444444444;
test=none;test=20170606;test=5555555555555555555;
test=none;test=20170606;test=5555555555555555555;
test=none;test=20170606;test=6666666666666666666;
test=none;test=20170606;test=7777777777777777777;
test=none;test=20170606;test=8888888888888888888;
test=none;test=20170606;test=9999999999999999999;
test=none;test=20170606;test=100000000000000000000;
test=none;test=20170606;test=11111111111111111111;

Output with unexpected values:

2222222222222222222 1111111111111111168
3333333333333333333 1111111111111111168
4444444444444444444 1111111111111111168
5555555555555555555 1111111111111110656
6666666666666666666 1111111111111111680
7777777777777777777 1111111111111110656
8888888888888888888 1111111111111111680
9999999999999999999 1111111111111110656
100000000000000000000 90000000000000000000

- , , , , - ... .

!:)

+4
1

. , , 2222222222222222222 - 1111111111111111111, 1111111111111111168 1111111111111111111.

. GNU Awk:

, awk 64- IEEE . , , 9,007,199,254,740,997, , , , 53 ; 53 . , C double, double. 64- IEEE, . ?

, , 64- , 2 ^ 53. 2 ^ 53 + 2, , gawk print 2 ^ 53 + 1 . , 64- , [-2 ^ 53, 2 ^ 53]. - awk, 64- , .

@EdMorton , , Awk MPFR, -M. . 15.3. .

+3

Source: https://habr.com/ru/post/1680032/


All Articles