>_ IzzyLab

Topic breakdown

The classic aggregation pattern in awk is an accumulator variable: it doesn't need to be declared, on first use it equals zero, and on each line the right field is added to it with the += operator. The addition happens on each line, while the total is printed once, so the print is moved into the END block, which runs after the pass over the whole file. This way a single number accumulates over the entire pass and is then redirected to a file.

What's checked

  1. /root/total.txt has the correct sum of quantities

What it looks like