0

We are using the following awk command in order to calculate the sum of the numbers

awk '{ sum += $0 } END { print sum }' /tmp/file-to-calculate.txt

example of the file

more /tmp/file-to-calculate.txt

    3.4    M
    54.2   M
    4.5    M
    3.5    M
    2.3    M
    89.6   M
    .
    .
    .

because the file include long list of numbers to sum , we get the following results number from awk

2.16626e+07

so how to change the awk in order to get readable integer number ( without "+07" )

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
jessica
  • 2,426
  • 24
  • 66
  • 2
    Please check if [How can I make awk not use scientific notation when printing small values?](https://stackoverflow.com/questions/12714155/how-can-i-make-awk-not-use-scientific-notation-when-printing-small-values) helps. – Wiktor Stribiżew May 18 '22 at 08:00
  • use `printf` with format `%f` – Bodo May 18 '22 at 08:01

0 Answers0