I want to sum the values of all rows in the column 3. How can I do this?
Input:
chr19 10 11 chr19 12 15 chr19 11 29 chr19 a0 20
Expected output:
75
NF is a predefined variable whose value is the number of fields in the current record. awk automatically updates the value of NF each time it reads a record. No matter how many fields there are, the last field in a record can be represented by $NF . So, $NF is the same as $7 , which is ' example.
awk '{SUM+=$3}END{print SUM}'
where $3 represent value of column 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With