Computing.Net > Forums > Programming > Help with shell script - Pattern search

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with shell script - Pattern search

Reply to Message Icon

Name: bob
Date: May 23, 2002 at 04:58:01 Pacific
Comment:

I have a access log file on the webserver. the log contains info on userids , date/time and page acccessed.
I need help with a shell scipt that can parse the file and compile a consilidated list of userids, and page accessed by time.

Here's an example of 2 records fom the file.

182.178.112.13 - - [23/May/2002:07:39:01 -0400] "GET /mai-cgi/Home.cgi?userid=114736 HTTP/1.0" 200 12098
182.178.112.13 - - [23/May/2002:07:39:01 -0400] "GET /mai-cgi/TopMenuBar4HomePage.cgi?userid=114736 HTTP/1.0" 200 1413

Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: junky_toof
Date: May 25, 2002 at 09:51:13 Pacific
Reply:

This is a job for awk, I am not going to
write you all the code: the date
reformatting would take a separate function
in any case to arrange the data ordinally.

A brief, untested, partial idea is this::

awk '

/\[.*:[0-9]+:[0-9]+[0-9]+-.*\]/ {
sub(/[.*:/,"",$0)
sub(/-.*\]/,"",$0)
dates[cnt++","NR] = $0
}

/\?userid=[0-9]+/ {
userids[ucnt++","NR] = $0
}

/\/[a-z]+-[a-z]\/[A-Za-z]+.cgi/ {
pages[pcnt++",",NR] = $0
}

Which gathers your data into three separate
arrays and is now ready for you to sort and
recalculate the data.

see if someone on comp.lang.awk wants to
write your program for you.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help with shell script - Pattern search

need some help with shell scripting www.computing.net/answers/programming/need-some-help-with-shell-scripting/16784.html

Shell Script with AWK www.computing.net/answers/programming/shell-script-with-awk/15486.html

help with vbs script www.computing.net/answers/programming/help-with-vbs-script-/8228.html