LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Grep command (https://www.linuxquestions.org/questions/linux-general-1/grep-command-4175494117/)

JJJCR 02-07-2014 03:31 AM

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.

TenTenths 02-07-2014 03:45 AM

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

You could try 07/Feb/2014.*asz instead

descendant_command 02-07-2014 03:48 AM

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.

TenTenths 02-07-2014 03:54 AM

Quote:

Originally Posted by descendant_command (Post 5113183)
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.

JJJCR 02-07-2014 03:56 AM

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.. ;)


All times are GMT -5. The time now is 10:20 AM.