Using nawk, how to sum all numbers in
8 6 2 7 3 5 1 9 4
I want the result to be sum = 45
This will work irrespective of the number of rows or columns. By using the record separator(RS) as space or a newline, every value is split into a separate line, and hence can be easily added.
You could also go with coreutils and bc:
If some columns should be omitted, e.g. if the input is like this:
Output in both cases: