Multiply field’s (column’s) entries and sum them up with awk
$ awk '{ sum = sum + $2 * $3 } END { print sum }' file.txt
You can write this command more concisely by using the abbreviation +=
for incrementing sum
1:
$ awk '{ sum += $2 * $3 } END { print sum }' file.txt
Let me know if this command can be shorten: https://yctct.com/contact
Maybe it is possible to use Datamash to do it.
The AWK Programming Language, Second Edition, Aho, Kernighan, Weinberger↩︎
personal computing command-line interface (cli) gnu linux trisquel shell literacy office applications wiki text processing awk spreadsheet stuff in the terminal offline