![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
what exactly have you tried so far?
|
|
#3
|
||||
|
||||
|
Arrays in awk (and php) are purely associative. So you can say
Code:
ip[$1]++; 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";
}
|
|
#4
|
|||
|
|||
|
So far !
done - thanks for the help !
Last edited by fusionX; 02-19-2008 at 10:04 PM. Reason: done. |
|
#5
|
|||
|
|||
|
check out what I had tried....
|
|
#6
|
|||
|
|||
|
la la la la la la -
Last edited by fusionX; 02-19-2008 at 10:04 PM. Reason: working |
|
#7
|
||||
|
||||
|
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.
|
||||
| Google The UNIX and Linux Forums |