Here is my file name countries
USSR 8650 262 Asia
Canada 3852 24 North America
China 3692 866 Asia
USA 3615 219 North America
Brazil 3286 116 South America
India 1269 637 Asia
Argentina 1072 26 South America
Sudan 968 19 Africa
Algeria 920 18 Africa
Assuming the second column is the total area, how would I total that column? Many thanks.
Forgot to mention that it can only be for all North American countries
area=0
total=0
for area in `grep "North America" countries | awk '{print $2}'`
do total=$(($total+$area))
done
echo $total
Example:
monitor:/tmp# area=0; total=0; for area in `grep "North America" countries | awk '{print $2}'`; do total=$(($total+$area)); done; echo $total
7467
HTH!
using awk..
awk '/North America/{s+=$2}END{print s}' data.file
awk '{n=n+$2}END{print n}' filename
summer_cherry,
The OP only wants to see the result for North America.
Best regards.
i got the same prob as the ts
anyone know how to do
1 IT 50
2 IT 40
3 Finance 200
4 MP 30
5 MP 10
6 HQ 30
how to get make it that i can get the total of IT which is 90 and display it like this
IT 90
MP 40
HQ 30
Finance 200
otheus
8
Similar, but use associative arrays to store the values.
awk ' { sum[$2]+=$3 } END { for (j in sum) print j,sum[j]; }'
Look the same but is not, you should start a new thread next time.