The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2008
new_buddy new_buddy is offline
Registered User
  
 

Join Date: May 2008
Posts: 11
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
The output should be like this format
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
I am using awk for this job. Really need for help. Thanks in advance
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
  #2 (permalink)  
Old 05-27-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Try:
Code:
awk 'NR>1{a[$1]++;b[$1]=b[$1]+$3}END{for (i in a) print i,a[i],b[i]}' file|sort -rn
  #3 (permalink)  
Old 05-27-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
Hi Klashxx,

NR>1 condition is not needed i think . Infact it should not be there

Thanks
Penchal
  #4 (permalink)  
Old 05-28-2008
new_buddy new_buddy is offline
Registered User
  
 

Join Date: May 2008
Posts: 11
It's work

Thanks you very much for your help.
It's working now.
Cheers..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0