Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
05-24-2007, 10:07 AM
|
#16
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
Code:
#!/bin/sh
awk 'BEGIN{SUBSEP="@"}
{
for (i=1;i<=NF;i++){
if ($i ~ /SRC/) {
sub(/^SRC=/,"",$i)
ip=$i
}
else if ($i ~ /DPT/){
sub(/^DPT=/,"",$i)
port=$i
array[ip,port]++
}
}
}
END{
for ( i in array ){
n=split(i, s, SUBSEP)
print s[1] " probed " s[2] " " array[i] " times"
}
}' "file"
output:
Code:
# ./test1.sh
127.0.0.1 probed 80 1 times
127.0.0.1 probed 984 2 times
10.0.2.15 probed 40390 4 times
10.0.2.15 probed 40414 2 times
127.0.0.1 probed 489 2 times
|
|
|
|
05-24-2007, 10:17 AM
|
#17
|
|
LQ Newbie
Registered: May 2007
Posts: 11
Original Poster
Rep:
|
Thank you thank you thank you!
Works perfectly, and stops me from banging my head against a wall.
Much appreciated!
Im gonna be cheeky now - can i just ask, what does the line 'n=split(i, s, SUBSEP)' do?
Thanks again.
Last edited by tenaciousbob; 05-24-2007 at 10:31 AM.
|
|
|
|
05-24-2007, 10:43 AM
|
#18
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
Quote:
|
Originally Posted by tenaciousbob
Thank you thank you thank you!
Works perfectly, and stops me from banging my head against a wall.
Much appreciated!
Im gonna be cheeky now - can i just ask, what does the line 'n=split(i, s, SUBSEP)' do?
Thanks again.
|
multidimensional arrays are created using concatenation of string indices. therefore if want to store like array[ip,port] , awk will concat to one string using default separater "\034". however i just chose to use "@" for visibility. when we view the array, they are something like this
Code:
array[127.0.0.1@80]
and use ++ to increment the count for identical ip and port. As for the n=split(i, s, SUBSEP) line, i just want to get back the values of ip and port (stored in s), so i can print your desired output. hope you understand.
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:54 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|