bug-grep
[Top][All Lists]
Advanced

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

bug#22656: How to grep two patterns in a line with correct coloring?


From: Zev Weiss
Subject: bug#22656: How to grep two patterns in a line with correct coloring?
Date: Mon, 11 Apr 2016 00:39:00 -0500
User-agent: Mutt/1.5.24 (2015-08-30)

On Sun, Apr 10, 2016 at 09:45:49PM -0700, Paul Eggert wrote:
This works for me:

grep --color=always -E 'word1|word2'


Isn't that a different search? The original question asked about colorizing both patterns in the output of

 grep word1 | grep word2

(i.e. lines that contain *both* word1 and word2), whereas egrepping for 'word1|word2' outputs lines that contain *either*.

Gary Johnson suggested

 grep --color=always word1 | grep word2

which seems like it should work in most cases, but would break down in cases where word2 overlaps a boundary of word1 (since the escape codes for colorizing the word1 match would throw off the matching of word2). So in full generality it seems like you'd have to do something like:

 grep word1 | grep word2 | grep -E 'word1|word2'

(so that the first two just filter and only the final one colorizes).

Granted,

 echo abc | grep -E --color 'ab|bc'

only colorizes the "ab" part of the output anyway (I'm assuming that's expected, and not itself a bug, but I'm not certain).


Zev






reply via email to

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