Review your favorite Linux distribution.
Go Back > Forums > > LQ Suggestions & Feedback
User Name
LQ Suggestions & Feedback Do you have a suggestion for this site or an idea that will make the site better? This forum is for you.
PLEASE READ THIS FORUM - Information and status updates will also be posted here.


Closed Thread
  Search this Thread
Old 06-10-2006, 11:39 AM   #1
LQ Newbie
Registered: Jun 2006
Posts: 12

Rep: Reputation: 0
Question Pattern match and counting script -->how to write ?

Hi Group,

See the following log file of apache (HTTPD).
I want a script which can calculate the busiest date. This file is long (very long) with the lines below: - - [03/Jan/2005:11:43:27 +1100] "GET" - - [03/Jan/2005:11:43:27 +1100] "GET" - - [03/Jan/2005:11:43:27 +1100] "GET" - - [04/Jan/2005:11:43:27 +1100] "GET" - - [05/Feb/2005:11:43:27 +1100] "GET" - - [05/Feb/2005:11:43:27 +1100] "GET" - - [04/Mar/2005:11:43:27 +1100] "GET" - - [04/Mar/2005:11:43:27 +1100] "GET" - - [06/Feb/2005:11:43:27 +1100] "GET" - - [06/Feb/2005:11:43:27 +1100] "GET" - - [06/Mar/2005:11:43:27 +1100] "GET" - - [06/Mar/2005:11:43:27 +1100] "GET"

I can do it with grep command as below, which works perfectly:

# less access.log |grep -c 03/Jan/2005

but with this I need to put the pattern manualli i.e. 03/Jan/2005.

Is there a good way to write this script which will automatically give me a busyiest day of the year. the file has more then 4 yrs access record so its only possible with a good script.

Any thought are welcome.

Old 06-10-2006, 12:11 PM   #2
LQ Guru
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
I think this is definitely the wrong forum (suggestions & feedback) for this post. Plus, don't post the same thread into multiple forums.
Old 06-10-2006, 12:12 PM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
In general, I wouldn't try to use a shell script to do this. However, in perl, it is only a few lines of code to parse an Apache log file. There are other equally suitable languages for the task. An alternative might be to use a ready-made log file analyzer.

--- rod.
Old 06-10-2006, 12:14 PM   #4
spirit receiver
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
This has been posted twice, I just gave a solution here:
Old 06-11-2006, 06:10 PM   #5
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 12,425

Rep: Reputation: 3308Reputation: 3308Reputation: 3308Reputation: 3308Reputation: 3308Reputation: 3308Reputation: 3308Reputation: 3308Reputation: 3308Reputation: 3308Reputation: 3308
// closed dupe.


Closed Thread

count, file, match, pattern, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
how to use the sed w option to redirect pattern match to file nickleus Linux - General 11 04-18-2006 08:34 AM
perl pattern match question lluciano Programming 4 02-28-2006 05:59 AM
svcadm: Pattern 'apache' doesn't match any instances xpucto Solaris / OpenSolaris 8 02-19-2006 07:30 AM
Procmail: match pattern then pass to shell script essdeeay Linux - Software 1 11-08-2004 02:19 PM > Forums > > LQ Suggestions & Feedback

All times are GMT -5. The time now is 04:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration