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: Paolo Bonzini
Subject: Re: Grep colors highlight all possible matches
Date: Wed, 20 Feb 2013 12:16:13 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

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



reply via email to

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