Say you have (as I do) a file /tmp/myFile.txt
containing a list of unrelated folders with their size, as follows:
1 | 7220 X03066659D/txt/20150109 |
And you want to sum the first column of every line to know the total. AWK at rescue!
1 | awk '{sum += $1} END {print sum} /tmp/myFile.txt' |
If there were a discriminant you would like to use (imagine you only need those starting with A
on second column) you can filter on AWK line (no need to grep)
1 | awk '$2 ~ /^A/ {sum += $1} END {print sum}' /tmp/myFile.txt |