LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-18-2012, 12:09 AM   #1
roopakl
Member
 
Registered: Sep 2011
Posts: 95

Rep: Reputation: Disabled
grep or egrep help


Hi All,
I want to search particular date logs from /var/log/httpd/access.log file. For example log file having entries as below
Code:
tail -n2 /var/log/httpd/access.log
192.168.223.105 - - [18/Dec/2012:11:14:38 +0530] "GET /favicon.ico HTTP/1.1" 404 287 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20120827 Firefox/16.0"
192.168.223.133 - - [18/Dec/2012:11:14:38 +0530] "GET /favicon.ico HTTP/1.1" 404 287 "-" "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20120827 Firefox/16.0"
I tried
Code:
grep -i "18/Dec/12" /var/log/httpd/access.log
egrep -i "18/Dec/12" /var/log/httpd/access.log
egrep -i "*18/Dec/12*" /var/log/httpd/access.log
egrep "*18/Dec/12*" /var/log/httpd/access.log
egrep '*18/Dec/12*' /var/log/httpd/access.log
egrep -i *'18/Dec/12'* /var/log/httpd/access.log
egrep -i '*18/Dec/12*' /var/log/httpd/access.log
But showing nothing. So need your kind help.

Last edited by roopakl; 12-18-2012 at 01:25 AM.
 
Old 12-18-2012, 01:25 AM   #2
roopakl
Member
 
Registered: Sep 2011
Posts: 95

Original Poster
Rep: Reputation: Disabled
Sorry, I disturbed you all, Actually the mistake was from my side. I was trying
Code:
grep "18/Dec/12" /var/log/httpd/access.log
instead
Code:
grep "18/Dec/2012" /var/log/httpd/access.log
 
Old 12-19-2012, 10:54 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Small mistakes like that can certainly trip you up!

Incidentally, this is wrong, even if you're using the right date format:

Code:
egrep -i "*18/Dec/12*" /var/log/httpd/access.log
grep uses regular expressions, not globbing (wildcard) patterns. While in globbing '*' has the meaning of "an unbroken string of characters of any type and length, including none", in regex it means "zero or more instances of the previous character". So on its own it's almost meaningless, and may even match something you don't want.

To get the wildcard behavior in regex you have to use ".*", with "." meaning "any character".

It's well worth taking the time to familiarize yourself with regex. Here are a few links for you:

http://mywiki.wooledge.org/RegularExpression
http://www.grymoire.com/Unix/Regular.html
http://www.regular-expressions.info/

And this link will give you a general overview of globbing (although it's actually written for the bash shell flavor of it and not everything mentioned is supported by other tools).

http://mywiki.wooledge.org/glob
 
1 members found this post helpful.
Old 12-19-2012, 11:12 AM   #4
roopakl
Member
 
Registered: Sep 2011
Posts: 95

Original Poster
Rep: Reputation: Disabled
Thanks David the H.
I really appreciate your explanation skill but not only in this thread, also in your other threads.

Last edited by roopakl; 12-19-2012 at 11:14 AM.
 
  


Reply



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
grep/egrep logical AND function? boozer_2 Linux - Newbie 11 04-10-2010 01:19 AM
how to do Logical AND with grep or egrep amit_pansuria Programming 2 08-09-2009 02:39 AM
Help with ls and grep/egrep kasthana Linux - Newbie 1 05-29-2008 01:06 PM
using grep and egrep in the terminal KumARan23 Linux - Newbie 3 11-11-2007 09:27 AM
Using Grep and Egrep linux-nerd Linux - General 5 10-10-2004 11:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:44 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration