LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

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

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


Hello,

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?

#!/bin/bash
for day in $d
do
grep -h "$day/$month/$year" *access_log* >> output.txt
done

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

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
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:
Code:
#!/bin/bash
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
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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.
 
  


Reply


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 12:34 AM.

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