GNU bug report logs -
#22656
How to grep two patterns in a line with correct coloring?
Previous Next
Reported by: Peng Yu <pengyu.ut <at> gmail.com>
Date: Sun, 14 Feb 2016 00:11:02 UTC
Severity: normal
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22656 in the body.
You can then email your comments to 22656 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-grep <at> gnu.org
:
bug#22656
; Package
grep
.
(Sun, 14 Feb 2016 00:11:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Peng Yu <pengyu.ut <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-grep <at> gnu.org
.
(Sun, 14 Feb 2016 00:11:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi,
I know that I can use this to grep two patterns. But it can not
highlight both patterns.
grep word1 FILE | grep word2
Or I can use the following. But it is cumbersome as I have to type
word1 and word2 twice. And this method is not scale if I want grep
multiple patterns. The coloring can not be just for word1 and word2
only.
grep -E 'word1.*word2|word2.*word1' logs
Could anybody let me know what is the best way to grep two patterns in
a line with correct coloring? Thanks.
--
Regards,
Peng
Information forwarded
to
bug-grep <at> gnu.org
:
bug#22656
; Package
grep
.
(Sun, 14 Feb 2016 03:14:01 GMT)
Full text and
rfc822 format available.
Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):
On 2016-02-13, Peng Yu wrote:
> Hi,
>
> I know that I can use this to grep two patterns. But it can not
> highlight both patterns.
>
> grep word1 FILE | grep word2
This seems to work:
grep --color=always word1 FILE | grep word2
Regards,
Gary
Reply sent
to
Paul Eggert <eggert <at> cs.ucla.edu>
:
You have taken responsibility.
(Mon, 11 Apr 2016 04:46:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Peng Yu <pengyu.ut <at> gmail.com>
:
bug acknowledged by developer.
(Mon, 11 Apr 2016 04:46:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 22656-done <at> debbugs.gnu.org (full text, mbox):
This works for me:
grep --color=always -E 'word1|word2'
Information forwarded
to
bug-grep <at> gnu.org
:
bug#22656
; Package
grep
.
(Mon, 11 Apr 2016 05:40:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 22656 <at> debbugs.gnu.org (full text, mbox):
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
Information forwarded
to
bug-grep <at> gnu.org
:
bug#22656
; Package
grep
.
(Mon, 11 Apr 2016 05:55:01 GMT)
Full text and
rfc822 format available.
Message #19 received at 22656 <at> debbugs.gnu.org (full text, mbox):
Zev Weiss wrote:
> 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)
I interpreted the original question the other way. Now that I reread it, it
appears to be ambiguous.
This bug report does have the flavor of someone trying to use debbugs.gnu.org to
solve a homework problem, which means I should probably stop now....
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 09 May 2016 11:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 9 years and 104 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.