How to use regular expression with grep

Hello all,

This should be something very simple but I am not that familiar with
grep (and unix in general).

But I'm trying to learn how to do this.

Let say I have a log file fall MyLog.log and it has lots of lines in
it. I'm trying to find the line with this string

YYYYDDMM HHMMSS [INFO] The time taken to process XYZ is 15


the thing is that XYZ is something that always change.

I tried (which demonstrate my not knowing this thing)

grep "The time taken to process * is 15" MyLog.log

And that simply doesnt works. I need the answer as soon as possbile.
In the meantime I'll go thorough google result on grep and regular
expression. But so far it looks like something that I can't
comprehend.

Appreciate any immediate reply to this thread!
harishashim [ Fr, 02 November 2007 05:47 ] [ ID #1860544 ]

Re: How to use regular expression with grep

On Nov 2, 9:47 am, harishas... [at] gmail.com wrote:
> Hello all,
>
> This should be something very simple but I am not that familiar with
> grep (and unix in general).
>
> But I'm trying to learn how to do this.
>
> Let say I have a log file fall MyLog.log and it has lots of lines in
> it. I'm trying to find the line with this string
>
> YYYYDDMM HHMMSS [INFO] The time taken to process XYZ is 15
>
> the thing is that XYZ is something that always change.
>
> I tried (which demonstrate my not knowing this thing)
>
> grep "The time taken to process * is 15" MyLog.log
>
> And that simply doesnt works. I need the answer as soon as possbile.
> In the meantime I'll go thorough google result on grep and regular
> expression. But so far it looks like something that I can't
> comprehend.
>
> Appreciate any immediate reply to this thread!


Try using grep "The time taken to process .* is" MyLog.log it should
help. '*' means 0 or more characters and since it is present after a
space it is trying to grep for "The time taken to process followed by
zero or more spaces and then followed by the string "is 15". Is this
your requirement or you need advance search ?.
ramesh.thangamani [ Fr, 02 November 2007 07:38 ] [ ID #1860547 ]

Re: How to use regular expression with grep

On Nov 2, 2:38 pm, rthangam <ramesh.thangam... [at] gmail.com> wrote:
> On Nov 2, 9:47 am, harishas... [at] gmail.com wrote:
>
>
>
> > Hello all,
>
> > This should be something very simple but I am not that familiar with
> > grep (and unix in general).
>
> > But I'm trying to learn how to do this.
>
> > Let say I have a log file fall MyLog.log and it has lots of lines in
> > it. I'm trying to find the line with this string
>
> > YYYYDDMM HHMMSS [INFO] The time taken to process XYZ is 15
>
> > the thing is that XYZ is something that always change.
>
> > I tried (which demonstrate my not knowing this thing)
>
> > grep "The time taken to process * is 15" MyLog.log
>
> > And that simply doesnt works. I need the answer as soon as possbile.
> > In the meantime I'll go thorough google result on grep and regular
> > expression. But so far it looks like something that I can't
> > comprehend.
>
> > Appreciate any immediate reply to this thread!
>
> Try using grep "The time taken to process .* is" MyLog.log it should
> help. '*' means 0 or more characters and since it is present after a
> space it is trying to grep for "The time taken to process followed by
> zero or more spaces and then followed by the string "is 15". Is this
> your requirement or you need advance search ?.

Thanks ... it works like a charm.

Best regards!
harishashim [ Fr, 02 November 2007 08:17 ] [ ID #1860548 ]

Re: How to use regular expression with grep

rthangam <ramesh.thangamani [at] gmail.com> writes:

> > grep "The time taken to process * is 15" MyLog.log

> Try using grep "The time taken to process .* is"


the character "*" on the shell matches anything. But as a regular
expression, it means "zero or more of the preceeding character set."


a* = matches zero or more a's
a*b = matches b, ab, aab, aaab, aaaab, etc.
[a-z]* = matches zero or more letters
. = matches any character
.* matches one or more characters
Maxwell Lol [ Fr, 02 November 2007 12:44 ] [ ID #1860559 ]

Re: How to use regular expression with grep

On Nov 1, 11:47 pm, harishas... [at] gmail.com wrote:
> Hello all,
>
> This should be something very simple but I am not that familiar with
> grep (and unix in general).
>
> But I'm trying to learn how to do this.
>
> Let say I have a log file fall MyLog.log and it has lots of lines in
> it. I'm trying to find the line with this string
>
> YYYYDDMM HHMMSS [INFO] The time taken to process XYZ is 15
>
> the thing is that XYZ is something that always change.
>
> I tried (which demonstrate my not knowing this thing)
>
> grep "The time taken to process * is 15" MyLog.log
>
> And that simply doesnt works. I need the answer as soon as possbile.
> In the meantime I'll go thorough google result on grep and regular
> expression. But so far it looks like something that I can't
> comprehend.
>
> Appreciate any immediate reply to this thread!
why do not you use search option .
vi MyLog.log
/The time taken to process

This should giveyou result
peoplesoft75 [ Sa, 03 November 2007 20:48 ] [ ID #1861408 ]
Linux » comp.unix.shell » How to use regular expression with grep

Vorheriges Thema: [zsh] full path of a script
Nächstes Thema: wget for downloading scientific papers