bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grep colors highlight all possible matches


From: Pollock, Wayne
Subject: Re: Grep colors highlight all possible matches
Date: Wed, 20 Feb 2013 11:54:30 +0000

Thanks, that would be helpful!  I already use sed, but the color option would 
work better for me.

-- 
Wayne Pollock

On Feb 20, 2013, at 6:16 AM, "Paolo Bonzini" <address@hidden> wrote:

> Il 10/02/2013 00:28, Pollock, Wayne ha scritto:
>> In teaching REs, I use grep and recently noticed
>> the colors highlight all possible matches, not
>> the one match as per POSIX's rules:
>> 
>>  echo 'abcdefabc' | grep '[abc]'
>> 
>> Should highlight only the first "a" (earliest match has
>> precedence, than longest).  Instead, every "a", "b", and
>> "c" is highlighted.  It would be my guess that grep historically
>> didn't need to know exactly what matched, just that something
>> did, so the code doesn't bother to apply any rules to determine
>> exactly what matched.
>> 
>> I don't mind the current behavior as a default, but there should
>> be some option to force grep to only highlight the one match,
>> as per BRE/ERE/PCRE rules of precedence.
>> 
> 
> We could add a --max-line-matches option.  It would affect --color and
> -o.  It would be mostly useful for -o, but would help you nicely as well. :)
> 
> For your task, in the meanwhile you can use
> 
>   echo 'abcdefabc' | sed 's/[abc]/|&|/'
> 
> Paolo

Please Note: 

Due to Florida's very broad public records law, most written communications to
or from College employees regarding College business are public records,
available to the public and media upon request.  Therefore, this email
communication may be subject to public disclosure.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]