Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-19-2010, 07:57 AM   #1
LQ Newbie
Registered: Oct 2009
Posts: 4

Rep: Reputation: 0
How to search date period in access log using grep


I have a three input day,month and year.
Currently i am using the following script to take the data.
Any grep advanced technique to avoid for loop?

for day in $d
grep -h "$day/$month/$year" *access_log* >> output.txt

Old 02-19-2010, 08:23 AM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,556
Blog Entries: 14

Rep: Reputation: 963Reputation: 963Reputation: 963Reputation: 963Reputation: 963Reputation: 963Reputation: 963Reputation: 963
Is day the word, abbreviation or the numeric? If the numeric does it get prepended with a 0 if it is the 1st through the 9th?

Instead of just d you could have d1, d2 & d3 - egrep (a/k/a grep -E) would then be the way to go:
egrep -h "$d1|$d2|$d3"/$month/$year *access_log* >> output.txt
In the above the items in the quotes are separated by the pipe symbol which means "or" in this context.

Last edited by MensaWater; 02-19-2010 at 08:26 AM.
Old 02-19-2010, 08:24 AM   #3
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 737Reputation: 737Reputation: 737Reputation: 737Reputation: 737Reputation: 737Reputation: 737
How is data getting into those variables? $d, $day, $month, $year

Does that script work as you have shown it?

Please show us a sample of the format used in the access log.

If you want an interactive script that takes data from the user, then you will have to have a loop.


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding date and time to Squid access.log jonette20 Linux - General 5 09-21-2009 07:41 AM
Grep Recursive Search Results Send To E-mail or Log? Knucklehead00 Linux - Newbie 2 06-05-2009 10:19 AM
grep does not care about file names beginning with period. stf92 Linux - Newbie 15 06-04-2009 07:27 PM
Script to grep log files based on system date cyclegar Programming 2 05-05-2009 06:08 PM
how to add date n time in proxy access.log sunlinux Linux - Networking 3 08-23-2007 06:54 AM

All times are GMT -5. The time now is 04:40 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