Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Summing values of a column using awk command

Tags:

awk

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

like image 810
Rashedul Islam Avatar asked Feb 11 '15 01:02

Rashedul Islam


People also ask

How do I use NF in awk?

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.


1 Answers

awk '{SUM+=$3}END{print SUM}' 

where $3 represent value of column 3

like image 82
repzero Avatar answered Oct 19 '22 22:10

repzero