Count total unique destination for source

Hi, need help how to count unique destination for the source ip. The file is contains 4 number of fields. Example of the file is here

src ip           dest ip     #of flows   total bytes
192.168.6.0  88.0.33.2      12           128
192.168.6.0  88.0.33.2      1             168
192.168.6.0  111.22.35.0   2             364
192.168.5.0  88.0.33.2      1             125
.....

I want to count the unique destination, total flows and total bytes per sorce ip. The output that I want it to be is this

192.168.6.0   2    15   660
192.168.5.0   1    1    125
.....

Is anyone can help me?

Your output seems worng, given your sample input.
Anyway, I suppose you need something like this:
(use nawk or /usr/xpg4/bin/awk on Solaris)

awk 'END {
  for (k in c) {
    split(k, t, SUBSEP)
    print t[1], c[k], f[k], b[k]
  }
}  
NR > 1 { 
  c[$1,$2] ++ 
  f[$1,$2] += $3 
  b[$1,$2] += $4 
  }' file

I am not sure what is wrong with my output. It is the output that I want.

From here, source 192.168.6.0 has 2 unique destination (88.0.33.22 and 111.22.35.0). and total of the flows is 12 (12+1+2) and total bytes 660 (128+168+364). So. from your code, I am trying to fit with my code. I am using awk -f count.awk. This are the lines in the count.awk file.

            {src[$1,$2]++
	total[$1,$2]=total[$1,$2]+$3 
	bytes[$1,$2]=bytes[$1,$2]+$4 
	}
 	END{
	for (i in src) print src " " src "\t" total "\t"  bytes 
	}

However, I got an error said that the src array is an illegal reference. Please help me. Need to solve this problem

Yep,
your requirement is more than clear,
sorry for the noise.
Use this code:

awk 'END {
  for (k in u) {
    printf "%s\t%s\t%s\t%s\n", 
	  k, u[k], f[k], b[k]
  }
}  
NR > 1 { 
  _[$1,$2]++ ? u[$1] : ++u[$1] 
  f[$1] += $3 
  b[$1] += $4 
  }' file

Many thanks for your help. I am now manage to produce the output I want. However, when I manually check, there is line of output is miscalculate. When I try remove the NR>1 then it works perfectly.

Many thanks for help. :smiley: :b:

NR > 1 excludes the first line:

src ip           dest ip     #of flows   total bytes

Perhaps you've already removed it?