>_ IzzyLab

Topic breakdown

The average is the sum divided by the count, so you need two quantities: a sum accumulator (add the field on each line via +=) and the number of lines, which you can count manually or take from the built-in NR. The division is performed in the END block, when the sum and the count are already collected over the full pass of the file. The data is chosen so that the result is an integer, so there's no need to think about rounding — the total is simply redirected to a file.

What's checked

  1. /root/avg.txt has the correct average

What it looks like