How to use regular expression with grep
How to use regular expression with grep
am 02.11.2007 05:47:10 von harishashim
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!
Re: How to use regular expression with grep
am 02.11.2007 07:38:30 von ramesh.thangamani
On Nov 2, 9:47 am, harishas...@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 ?.
Re: How to use regular expression with grep
am 02.11.2007 08:17:43 von harishashim
On Nov 2, 2:38 pm, rthangam wrote:
> On Nov 2, 9:47 am, harishas...@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!
Re: How to use regular expression with grep
am 02.11.2007 12:44:26 von Maxwell Lol
rthangam 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
Re: How to use regular expression with grep
am 03.11.2007 20:48:49 von peoplesoft75
On Nov 1, 11:47 pm, harishas...@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