![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to check Null values in a file column by column if columns are Not NULLs | Mandab | Shell Programming and Scripting | 7 | 03-15-2008 09:57 AM |
| sum total by column | thh | Shell Programming and Scripting | 5 | 11-25-2007 02:41 AM |
| Finding the most common entry in a column | Donkey25 | Shell Programming and Scripting | 12 | 11-22-2007 12:16 PM |
| grep running total/ final total across multiple files | MrAd | UNIX for Dummies Questions & Answers | 5 | 05-08-2007 02:03 PM |
| Finding a column in a flatfile | peter.herlihy | UNIX for Dummies Questions & Answers | 3 | 01-07-2002 08:08 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Finding the total of a column using awk
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. |
|
||||
|
Code:
area=0
total=0
for area in `grep "North America" countries | awk '{print $2}'`
do total=$(($total+$area))
done
echo $total
Example: Code:
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! Last edited by TheOther1; 04-21-2008 at 12:18 AM.. |
![]() |
| Bookmarks |
| Tags |
| statistical calculator, sum, sum by column, summing group |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|