Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cumulative total for each line 1

Status
Not open for further replies.
Apr 8, 2014
13
US
Example file:
sda 0.00 0.99 7.92 55.45 95.05 815.84 14.38 0.06 1.00 0.88 5.54
sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdd 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda 0.00 0.00 4.00 9.00 32.00 200.00 17.85 0.06 4.92 4.62 6.00
sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdd 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda 0.00 0.99 7.92 55.45 95.05 815.84 14.38 0.06 1.00 0.88 5.54
sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdd 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

Code:
# awk '{dev[i]=$1; await[j]=$10; for (i in dev); for (j in await); print dev[i]" "await[j]}' x
which prints this extracted sample data:
Code:
sda 3.45
sdb 0.00
sdc 0.00
sdd 0.00
sda 2.90
sdb 0.00
sdc 0.00
sdd 0.00
sda 0.00
sdb 0.00
sdc 0.00
sdd 0.00

But what I want is a cumulative total for each device instead of a line for each (for example):
sda 19.32
sdb 2.44
sdc 8.00
sdd 0.00
...
...
sdak 0.81

There may be tens or hundreds of devices.
Thanks
 
Something like this ?
Code:
awk '{await[$1]+=$10}END{for(j in await)print j" "await[j]}' x

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top