GNU bug report logs - #30686
How to color matched region but also show the nearby context noncolored in characters or words?

Previous Next

Package: grep;

Reported by: Peng Yu <pengyu.ut <at> gmail.com>

Date: Sat, 3 Mar 2018 04:05:01 UTC

Severity: normal

Tags: notabug

Done: Bob Proulx <bob <at> proulx.com>

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 30686 in the body.
You can then email your comments to 30686 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#30686; Package grep. (Sat, 03 Mar 2018 04:05:01 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. (Sat, 03 Mar 2018 04:05:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Peng Yu <pengyu.ut <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: How to color matched region but also show the nearby context
 noncolored in characters or words?
Date: Fri, 2 Mar 2018 22:04:01 -0600
Hi,

I am looking for a feature similar to -A -B -C but not based on lines,
but based on characters or even words. Is it possible with the current
version of grep?

In the following example, I'd like to show the matched region as well
as 3 characters before and after it. But the 3 characters before and
after the match is also showed.

grep --color -o -P '.{0,3}a.{0,3}' <<< '+++++++++++++++++a++++++++++++++++++++'

-- 
Regards,
Peng




Added tag(s) notabug. Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Sun, 04 Mar 2018 01:27:01 GMT) Full text and rfc822 format available.

Reply sent to Bob Proulx <bob <at> proulx.com>:
You have taken responsibility. (Sun, 04 Mar 2018 01:27:02 GMT) Full text and rfc822 format available.

Notification sent to Peng Yu <pengyu.ut <at> gmail.com>:
bug acknowledged by developer. (Sun, 04 Mar 2018 01:27:02 GMT) Full text and rfc822 format available.

Message #12 received at 30686-done <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Peng Yu <pengyu.ut <at> gmail.com>
Cc: 30686-done <at> debbugs.gnu.org
Subject: Re: bug#30686: How to color matched region but also show the nearby
 context noncolored in characters or words?
Date: Sat, 3 Mar 2018 18:26:28 -0700
tags 30686 + notabug
thanks

Peng Yu wrote:
> I am looking for a feature similar to -A -B -C but not based on lines,
> but based on characters or even words. Is it possible with the current
> version of grep?
>
> In the following example, I'd like to show the matched region as well
> as 3 characters before and after it. But the 3 characters before and
> after the match is also showed.
> 
> grep --color -o -P '.{0,3}a.{0,3}' <<< '+++++++++++++++++a++++++++++++++++++++'

Those three characters before and after as you say are also part of
the pattern and are also part of the match.  If you want to then only
color a subset in a second grep you can always do that.

  grep -o -P '.{0,3}a.{0,3}' <<< '+++++++++++++++++a++++++++++++++++++++' | grep --color 'a'
  +++a+++
     ^ only the 'a' is highlighted

Bob




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 01 Apr 2018 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 174 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.