[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [bug #22100] Enhancement request:
From: |
Ed Avis |
Subject: |
RE: [bug #22100] Enhancement request: |
Date: |
Tue, 12 Feb 2008 10:55:23 -0000 |
Tony Abou-Assaleh wrote:
>> % grep -E --context=10 oranges --and '[0-9]'
>
>You can do this both in grep (using -z) and in awk (by
>changing the record separator) and then matching for \n the
>desired number of times.
>
>The and operator can be done as follows:
>
>grep -E '(re1.*re2)|(re2.*re1)'
That doesn't work for all cases, for example (with -E)
re1=^hello
re2=^\w+
But if you stick to plain string-generating expressions, without anchors,
lookbehind or other exotic features then it does work.
I wonder if perl5 so-called regular expressions are 'closed under and' in this
way. Or if a perl5 regexp can be used to give the conjunction of two plain
grep regexps, but not necessarily of two perl5 regexps.
As for --not, perl5 regexps do support negation, I think: the pattern ^(?!x)$
matches all lines except those matching ^x$.
>I haven't formally tested this in grep (only in Perl), but I
>think chaining grep expressions is faster in most cases than
>using a single complex expression.
Does grep's optimizer not have some rules it uses to turn a single expression
into a conjunction or disjunction of smaller expressions? Certainly it would
be more parallelizable.
>Making grep do more with less is on my radar, but it is not a
>priority at the moment. There are some serious bugs that need
>to be fixed first.
Understood.
--
Ed Avis <address@hidden>
>-----Original Message-----
>From: Tony Abou-Assaleh [mailto:address@hidden
>Sent: Tuesday, February 12, 2008 5:56 AM
>To: Ed Avis
>Cc: address@hidden
>Subject: Re: [bug #22100] Enhancement request:
>
>> IMHO, context matching is a good reason why it is more powerful (and
>> not just syntactic icing or making the search faster) to support
>> matching two patterns at once. I don't think there is a
>> straightforward awk equivalent, or grep-pipeline equivalent, to
>>
>
>In terms of "power", grep regexp can do a lot. Sure it gets
>complicated, but the usage is less common, and for the rare
>cases it can be done.
>
>I haven't formally tested this in grep (only in Perl), but I
>think chaining grep expressions is faster in most cases than
>using a single complex expression.
>
>Making grep do more with less is on my radar, but it is not a
>priority at the moment. There are some serious bugs that need
>to be fixed first.
>
>Cheers,
>
>TAA
>
>--
>Tony Abou-Assaleh
>Email: address@hidden
>Web site: http://tony.abou-assaleh.net
>
>______________________________________________________________________
>This email has been scanned by the MessageLabs Email Security System.
>For more information please visit
>http://www.messagelabs.com/email
>______________________________________________________________________
>
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________