![]() |
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 |
| finding duplicate files by size and finding pattern matching and its count | jerome Sukumar | Shell Programming and Scripting | 2 | 12-01-2006 04:20 AM |
| How to count the record count in an EBCDIC file. | oracle8 | UNIX for Dummies Questions & Answers | 1 | 07-26-2006 07:22 PM |
| How to Achive IP address through MAC(Ethernet) address | krishnacins | IP Networking | 3 | 08-29-2005 08:45 PM |
| Matching '/' in SED | bestbuyernc | Shell Programming and Scripting | 5 | 07-19-2005 04:38 PM |
| network address and broadcast address? | pnxi | UNIX for Dummies Questions & Answers | 7 | 11-10-2003 11:29 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Awk to count matching IP address
Hi all,
I am kinda new to unix and shell programming. I am stucked with the raw data to do the filtering things. Generally, the output should count unique connected destination for each source and total of flows for it. Here is the example of input file: Code:
Source IP Dest IP No. of Flows 222.233.123.136 192.168.129.197 9 221.241.57.125 192.168.129.197 22 221.241.57.125 192.168.128.210 1 221.187.240.145 192.168.129.197 6 221.128.134.247 192.168.129.197 18 221.128.134.247 192.168.129.1 20 Code:
222.233.123.136 1 9 221.241.57.125 2 23 221.187.240.145 1 6 221.128.134.247 2 38 Here is the piece of my coding. Code:
awk 'BEGIN{SUBSEP="@"}
count=0
{ for(i=1;i < NF;i++)
{ if ($i==$1)
{
src=$1
conn=$3
count++
}
}
{
if ($1==src)
{
while (count>1)
{ conn += $3 }
}
}
unique[src,conn]++
}
END{
for (i in unique){
n=split(i,u,SUBSEP)
print u[1]" " unique[i]" "u[2]
}
}' tcpfile.sorted | sort -rn >> tcpfile.unique
}
Last edited by Yogesh Sawant; 05-27-2008 at 07:22 AM.. Reason: added code tags |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|