![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 sort, and count unique data all at once? | amatuer_lee_3 | Shell Programming and Scripting | 16 | 04-14-2009 10:22 PM |
| Source and Target count checking | ksmbabu | Shell Programming and Scripting | 2 | 04-03-2008 03:57 AM |
| grep running total/ final total across multiple files | MrAd | UNIX for Dummies Questions & Answers | 5 | 05-08-2007 01:03 PM |
| Byte Rate to/from a source/destination | cubs0729 | UNIX for Advanced & Expert Users | 1 | 08-08-2005 04:55 PM |
| Script to count unique number of user loged in | elchalateco | Shell Programming and Scripting | 1 | 09-30-2002 11:32 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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
HTML Code:
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 ..... HTML Code:
192.168.6.0 2 15 660 192.168.5.0 1 1 125 ..... |
|
||||
|
I am not sure what is wrong with my output. It is the output that I want.
Quote:
Code:
{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[i] "\t" total[i] "\t" bytes[i]
}
|
|
|||||
|
Yep,
your requirement is more than clear, sorry for the noise. Use this code: 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
|
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|