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!

sum from one variables associated for other 1

Status
Not open for further replies.

meels

Technical User
May 10, 2002
5
0
0
CA
Hello,

I have the following file
210.255.0.1 10.0.0.101 70
210.255.0.2 10.0.0.103 71
210.255.0.2 10.0.0.105 72
210.255.0.1 10.0.0.115 73
210.255.0.1 10.0.0.105 74
210.255.0.3 10.0.0.105 75
210.255.0.2 10.0.0.112 76
210.255.0.1 10.0.0.111 77

I need to get the for each variable ($1) the corresponding sum on $3

As follows

Total no'' of bytes for 210.255.0.1 = 70+73+74+77=294
Total no'' of bytes for 210.255.0.2 = 219
Total no'' of bytes for 210.255.0.3 = 75

I am new to awk and beginner in programming.

Thanks in advance,
meels
 
nawk -f meels.awk file

Code:
{
   arr[$1] +=$3
}

END {
   for (i in arr)
      printf("Total no'' of bytes for %s = %d\n", i,arr[i]);
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top