From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 02 23:04:13 2018 Received: (at submit) by debbugs.gnu.org; 3 Mar 2018 04:04:13 +0000 Received: from localhost ([127.0.0.1]:41725 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eryP7-0003E7-AQ for submit@debbugs.gnu.org; Fri, 02 Mar 2018 23:04:13 -0500 Received: from eggs.gnu.org ([208.118.235.92]:37095) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eryP5-0003Du-HV for submit@debbugs.gnu.org; Fri, 02 Mar 2018 23:04:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eryOz-0004M0-Jh for submit@debbugs.gnu.org; Fri, 02 Mar 2018 23:04:06 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:60642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eryOz-0004Lu-GE for submit@debbugs.gnu.org; Fri, 02 Mar 2018 23:04:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eryOy-0007Dx-En for bug-grep@gnu.org; Fri, 02 Mar 2018 23:04:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eryOx-0004KT-Ka for bug-grep@gnu.org; Fri, 02 Mar 2018 23:04:04 -0500 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:56205) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eryOx-0004Jg-DI for bug-grep@gnu.org; Fri, 02 Mar 2018 23:04:03 -0500 Received: by mail-wm0-x22b.google.com with SMTP id q83so6557804wme.5 for ; Fri, 02 Mar 2018 20:04:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=T4r4uZspoc48CK0k9AxTOB31jMhm1Ej7uTrvMNYcB44=; b=Y74mpJ5SEMmOFWgyuFLgp/RuclZwLo3qyJBeOJ9/jzaxTjQPraR8LJuXJVyP5X+BmZ +KaNuajB3VnWrHVrDIJ1WGw+aEK9vBCYpW7UnrYpENCFBwk5PVCs0vX18TofT3nJpyBO 1QUdmENYHlypYJlj0NsUSGfnCoAK8fM3tUYRMgrv4/ENHbsMvYRGo/1D+kwBnMZ09In1 3Brs0Zd0Paq35x3hbE2uEggzlP0MIpCczaWdapiB6QGzl9iTNn8CatsNU7ViQzZJDJIG 0ZmWdfysNluCeSRru4hbDO85kP/xakyuwh60wh8tQ9/9Iqy6cAmwJxuWKqG8lpUm2BFw b9fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=T4r4uZspoc48CK0k9AxTOB31jMhm1Ej7uTrvMNYcB44=; b=e6ZO6RL/RQDs8ArDvP0QHAOo38GV4zfxzO5gEiyYlUiV577d6jpvPXGzBzEB7SDZ6q 5ts3E3MnIMO7IO1N0/zD7QQPNsdAChu2hE+H0HQNiw52yZtiI/pGE10msaphgon7G3qK Vz5sydetk72/W9cyDWT/Xu4vq4MBYjomT9PaPToQ12jJu9TgWQEz43PDsvc78oQqeZZP RZ3qk/LoND+hQh9Rb0KPd5GAh78x3r2voDtPhRnU9gi6rEPMlcoYnkhGA9AkrQHWrwmk 7KEAUds1ndhPIOmomHYLn0QZWrDDErZyn34Ljj8ee71ZINJA/apwsYmswgKBik98OWYm zW4g== X-Gm-Message-State: APf1xPCWvs9KvcFR5BlKJHw4EO4u37TszHunyw4Dq8B+dICfg30s0tvT W7p6jlc0em3IP7HwBSDolRWbe81WpR4OkS2FThcqmT1I X-Google-Smtp-Source: AG47ELth2YKxQ3TLYk58EsLm/u4aVw2Rtu5vv0f5FOvv7St7pVm+6cmq3n5f7gulrShU1i+thQRbqE3vwQARr37p1Qc= X-Received: by 10.80.212.43 with SMTP id t43mr9750538edh.53.1520049842047; Fri, 02 Mar 2018 20:04:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.175.161 with HTTP; Fri, 2 Mar 2018 20:04:01 -0800 (PST) From: Peng Yu Date: Fri, 2 Mar 2018 22:04:01 -0600 Message-ID: Subject: How to color matched region but also show the nearby context noncolored in characters or words? To: bug-grep@gnu.org Content-Type: text/plain; charset="UTF-8" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) 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 From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 03 20:26:36 2018 Received: (at control) by debbugs.gnu.org; 4 Mar 2018 01:26:36 +0000 Received: from localhost ([127.0.0.1]:43378 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esIQ8-000306-6K for submit@debbugs.gnu.org; Sat, 03 Mar 2018 20:26:36 -0500 Received: from havoc.proulx.com ([96.88.95.61]:32958) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esIQ6-0002zm-Oq; Sat, 03 Mar 2018 20:26:35 -0500 Received: from joseki.proulx.com (localhost [127.0.0.1]) by havoc.proulx.com (Postfix) with ESMTP id 0A99B1C76; Sat, 3 Mar 2018 18:26:29 -0700 (MST) Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id BDC082125A; Sat, 3 Mar 2018 18:26:28 -0700 (MST) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 98CB92DC6B; Sat, 3 Mar 2018 18:26:28 -0700 (MST) Date: Sat, 3 Mar 2018 18:26:28 -0700 From: Bob Proulx To: Peng Yu Subject: Re: bug#30686: How to color matched region but also show the nearby context noncolored in characters or words? Message-ID: <20180303182215108463010@bob.proulx.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.3 (2018-01-21) X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: control Cc: 30686-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) 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 From unknown Sun Sep 21 07:50:27 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 01 Apr 2018 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator