Re: [Hampshire] Any grep gurus here?

Top Page

Reply to this message
Author: Stuart Sears
Date:  
To: lug, Hampshire LUG Discussion List
Subject: Re: [Hampshire] Any grep gurus here?
On 06/03/11 17:42, Vic wrote:
>
> Hi All.
>
> I need some help with regexes in grep.
>
> I'm trying to search for a pattern along the lines of:
>
> foo(bar
>
> Note that there is no closing bracket.
>
> Like an eejit, I thought a regex of
>
> foo\(.*
>
> would match that - but grep barfs. It tells me
>
> grep: Unmatched ( or \(


Escaping the ( turns **on** it's special meaning to grep, which uses
standard, not extended regex. It differs from python/awk/perl in this sense.

grep 'foo\(bar' is expecting to see a closing \) later in the pattern to
signify the end of a capturing group.

grep 'foo(bar' treats the ( as just another character. This is likely
what you want here.


Stuart
--
Stuart Sears RHCA etc.
"It's today!" said Piglet.
"My favourite day," said Pooh.