The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk arrays imonthejazz Shell Programming and Scripting 1 09-21-2007 06:29 AM
arrays in awk??? craigsky Shell Programming and Scripting 3 08-27-2007 06:13 PM
ksh script - arrays sidamin810 Shell Programming and Scripting 13 07-18-2005 12:07 AM
KSH and arrays whited05 Shell Programming and Scripting 1 06-24-2005 09:07 AM
Two or more arrays in Awk nitin UNIX for Advanced & Expert Users 1 12-10-2001 06:37 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-10-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
Need Help with awk and arrays

now its owkring - thanks fo rthe help all .

Last edited by fusionX; 02-19-2008 at 10:03 PM. Reason: changed.
Reply With Quote
Forum Sponsor
  #2  
Old 02-10-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
what exactly have you tried so far?
Reply With Quote
  #3  
Old 02-10-2008
otheus's Avatar
Moderator ala Mode
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 653
Arrays in awk (and php) are purely associative. So you can say

Code:
ip[$1]++;
Getting the busiest date and hour pretty much requires perl, but it's possible to do in gawk and maybe nawk. You'll need the mktime function in the least. It's ugly and you need to populate the full months table and some additional parsing.

Code:
BEGIN { m["Jan"]="01"; m["Feb"]="02"; } # and so on for all months
{ 

# split time field into numbers and letters
split($4,lt,"[^0-9a-zA-Z-]*"); 
# construct timestamp into internal unix representation
ts=mktime( lt[4] " " m[lt[3]] " " lt[2]  " " lt[5]  " " lt[6]  " " lt[7]  " " lt[8]); 
# you don't care about minutes and seconds, so just replace lt[7] and lt[6] with 0's. You could make *two* timestamps -- one for just the days (hours 0'd out) and another for just the hours (always Jan-1-1970, but with the hour filled in).

# bump count for this ip address
ip[$1]++; 
# 
day[ts]++;
}

END { 
  # find busiest day
  frequency=-1; busiest=-1;
  for (d in day) {
   if (day[d] > frequency) {
      frequency=day[d];
      busiest=d;
   }
  }
  print "busiest day: " busiest " hit " frequency " times";
  
}
Reply With Quote
  #4  
Old 02-10-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
So far !

done - thanks for the help !

Last edited by fusionX; 02-19-2008 at 10:04 PM. Reason: done.
Reply With Quote
  #5  
Old 02-10-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
check out what I had tried....
Reply With Quote
  #6  
Old 02-10-2008
Registered User
 

Join Date: Jan 2008
Posts: 9
Exclamation

la la la la la la - its owkring now.

Last edited by fusionX; 02-19-2008 at 10:04 PM. Reason: working
Reply With Quote
  #7  
Old 02-11-2008
otheus's Avatar
Moderator ala Mode
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 653
Quote:
Originally Posted by fusionX View Post
I only get this output with your code:
busiest day: -1 hits 1 times.
First, finish filling out the months table in the BEGIN block. Second, the time-zone doesn't correctly get registered. Replace lt[8] with $5. Third, feel free to insert "print" statements to get some debugging output. I saw only a few lines of the log file, and I tested my code only against those liens.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0