0

dummy.txt has the following data

3 19108601157904265

when I am trying to do arithmetic calculations using the below command

awk '{ print $1, ($1-1) * $2 }' dummy.txt

I am getting the answer as

3 38217202315808528

But it should be

3 38217202315808530

Normal command line calculation gives me expected value.

>a=2
>b=19108601157904265
>echo $(( a * b ))
>38217202315808530

Not sure why I am getting a lesser value than the actual multiplication. Thanks in advance.

Solution given in the question "Printing long integers in awk" works if the gawk version is greater than 4.1 whereas my current current version of gawk is older one.

Sekar Ramu
  • 343
  • 1
  • 2
  • 11
  • awk --bignum '{ print $1, ($1-1) * $2 }' dummy.txt solved the issue. --bignum does the work. – Sekar Ramu Feb 15 '19 at 08:25
  • @RavinderSingh I have rolled back your edit of the deleted answer; merely deleting it should be sufficient, please don't also edit it to remove the answer attempt. – tripleee Feb 15 '19 at 08:35
  • @tripleee, sorry I am not sure about that process. Why I am removing it because I understood requirement wrongly, so added that note in it. Thank you for letting me know. But 1 question, could you please do let me know why deleted answer can't be edited, if you don't mind please. – RavinderSingh13 Feb 15 '19 at 08:43
  • 1
    Deleting your answer it quite sufficient without also vandalizing it -- you just add another speed bump if someone wants to see what you actually did there, and having the deleted answer visible to 20k+ users potentially saves time from somebody who was drawing the same conclusion you did. – tripleee Feb 15 '19 at 08:45

0 Answers0