LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-07-2014, 03:31 AM   #1
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,779

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
Cool Grep command


hello guys, i have this pattern of logs which is kinda long and huge..

[08/Jan/2010 17:16:36] Result: delivered, Status: 2.0.0 , Remote-Host: 127.0.0.1, Msg-Id: <-asz@unknown.net>

[07/Feb/2014 17:16:36] Result: delivered, Status: 2.0.0 , Remote-Host: 127.0.0.1, Msg-Id: <-asz@unknown.net>

I tried to filter using this grep command:

grep -E 'asz|07/Feb/2014' list.log

I basically want to filter asz for the date of 07/Feb/2014.

But the results includes 2010 to 2014.

How do I use grep to filter the word "asz" for a particular date specified on the command?

Thank you.

Last edited by JJJCR; 02-07-2014 at 03:32 AM. Reason: edit
 
Old 02-07-2014, 03:45 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,070

Rep: Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298
From (fuzzy) memory, in your expression asz|07/Feb/2014 the | acts as "or" not "and"

You could try 07/Feb/2014.*asz instead
 
1 members found this post helpful.
Old 02-07-2014, 03:48 AM   #3
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,732

Rep: Reputation: 558Reputation: 558Reputation: 558Reputation: 558Reputation: 558Reputation: 558
There's probably a smart way with a single grep, but I don't know it, so I just pipe it to a second grep.
 
Old 02-07-2014, 03:54 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,070

Rep: Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298Reputation: 1298
Quote:
Originally Posted by descendant_command View Post
There's probably a smart way with a single grep, but I don't know it, so I just pipe it to a second grep.
To be honest thats also what I'd probably do rather than work out the required expression.
 
1 members found this post helpful.
Old 02-07-2014, 03:56 AM   #5
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,779

Original Poster
Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
hi TenTenths, yup it works..

actually, i tried this command:

grep -E "asz.*07/Feb/2014" list.log it still includes other years..

so when using the grep if the text to be search is on the left the pattern should be on the left also.. hmmm...

but when I reversed it as what you suggested it works..

For other people who might bump to this post..

the grep search for two patterns with an AND expression

here's the command, courtesy of TenTenths

Quote:
grep -E "07/Feb/2014.*asz list.log


---------- Post added 02-07-14 at 04:57 AM ----------

Simple way and works..is what matter most... hehehe...

Thanks TenTenths..
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with the cut command..or should I be using the grep command? ProAm500 Linux - Newbie 15 05-01-2013 04:01 AM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
[SOLVED] run ps|grep command by script/command line ... ERROR: Unsupported option (BSD syntax) masuch Programming 4 05-23-2012 04:13 AM
How to pass the result of a command to another command (like grep) desb01 Programming 4 06-25-2009 12:09 PM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 04:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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