From unknown Wed Aug 20 05:18:08 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#22656 <22656@debbugs.gnu.org> To: bug#22656 <22656@debbugs.gnu.org> Subject: Status: How to grep two patterns in a line with correct coloring? Reply-To: bug#22656 <22656@debbugs.gnu.org> Date: Wed, 20 Aug 2025 12:18:08 +0000 retitle 22656 How to grep two patterns in a line with correct coloring? reassign 22656 grep submitter 22656 Peng Yu severity 22656 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 13 19:10:12 2016 Received: (at submit) by debbugs.gnu.org; 14 Feb 2016 00:10:12 +0000 Received: from localhost ([127.0.0.1]:38427 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aUkGR-0000qj-RV for submit@debbugs.gnu.org; Sat, 13 Feb 2016 19:10:12 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55263) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aUkGQ-0000qX-9H for submit@debbugs.gnu.org; Sat, 13 Feb 2016 19:10:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUkGK-0003wQ-HG for submit@debbugs.gnu.org; Sat, 13 Feb 2016 19:10:05 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:37439) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUkGK-0003wL-FJ for submit@debbugs.gnu.org; Sat, 13 Feb 2016 19:10:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUkGJ-0005yj-Lj for bug-grep@gnu.org; Sat, 13 Feb 2016 19:10:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUkGI-0003vo-Sw for bug-grep@gnu.org; Sat, 13 Feb 2016 19:10:03 -0500 Received: from mail-io0-x229.google.com ([2607:f8b0:4001:c06::229]:33753) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUkGI-0003vc-NF for bug-grep@gnu.org; Sat, 13 Feb 2016 19:10:02 -0500 Received: by mail-io0-x229.google.com with SMTP id z135so56882762iof.0 for ; Sat, 13 Feb 2016 16:10:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=iPB0O3PL6WplKldoZYrliLoyxj16jkJzAEyCNYv0RRc=; b=wW7zv3pRt4oVBm7+yddXD2wVmj1WEDzGoj207gZKmejR9KUCOxCjlV16wb7gzpo7Kv EZMy/0VDZ3VW6gBEwqM+xu2LnFqO+0lwm7UIjRIbFrREBIojL0oTb/AlcIOX1IqeU8IT qRyqyEBj+D25DCUflDoIAhqYC+y0ESs4IHpijlml/aW7j6xqrrL9vGM5aQHBpyi+G3Ad rU7M8hYHh61d6nFGNJbwCMuIjdQoMsqyEUaYi2t76lrAaKAyJXYP/3xoJYB48ik9hTau ne73mHHneV7K93jDcQGvA7rZpCXXwImXe+PpvOdF0g40DL6Sq1SmUeLk1wXn8hhKWAj1 dprA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=iPB0O3PL6WplKldoZYrliLoyxj16jkJzAEyCNYv0RRc=; b=P6guD84kWW9FFW2fhQ41lPemSGI17Iet1fnwvh42KLmgD4CmnMHyljVxjnwctgzw0V Pk55krnUUnAzi0U5FLANTLrovNHH0pIngahAiSd7A8po0pgGpqI/yVFKfYR/5yDe0Bc8 ZLqO+OoLutEMhG/Wa21Nxhb2qidIkl93Vi3shYMkUCAWPYK73l/RLqLE2Ec856ZEioXY ST1FPAnUNHkwT6dmC6ip8GzSjYbuukEVVCS/EkW70Hn3XeJBiL9fzmVuTUcFi2RwSytk 4x+0OdHUe/F/KbuquSZtJbx8UyY+2+878YZjzBB64bmzTbKVnNrYEI3hU0wRux2pfEiz zxtQ== X-Gm-Message-State: AG10YOQzd4BUR9m4DHaUhBRuKjGdOC73ZqUy+CB4EtIZQxySyvnnCa2hk0tHqT644tjIfnREQy9f77vuHlRC0g== MIME-Version: 1.0 X-Received: by 10.107.164.212 with SMTP id d81mr11383481ioj.169.1455408601964; Sat, 13 Feb 2016 16:10:01 -0800 (PST) Received: by 10.107.166.77 with HTTP; Sat, 13 Feb 2016 16:10:01 -0800 (PST) Date: Sat, 13 Feb 2016 18:10:01 -0600 Message-ID: Subject: How to grep two patterns in a line with correct coloring? From: Peng Yu To: bug-grep@gnu.org Content-Type: text/plain; charset=UTF-8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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 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 From debbugs-submit-bounces@debbugs.gnu.org Sat Feb 13 22:13:02 2016 Received: (at submit) by debbugs.gnu.org; 14 Feb 2016 03:13:03 +0000 Received: from localhost ([127.0.0.1]:38433 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aUn7O-0005DY-MQ for submit@debbugs.gnu.org; Sat, 13 Feb 2016 22:13:02 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57500) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aUn7M-0005D4-UJ for submit@debbugs.gnu.org; Sat, 13 Feb 2016 22:13:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUn7G-0000J5-WD for submit@debbugs.gnu.org; Sat, 13 Feb 2016 22:12:55 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: *** X-Spam-Status: No, score=3.3 required=5.0 tests=BAYES_50, RECEIVED_FROM_WINDOWS_HOST autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:33696) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUn7G-0000J1-TL for submit@debbugs.gnu.org; Sat, 13 Feb 2016 22:12:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUn7G-0001PZ-4E for bug-grep@gnu.org; Sat, 13 Feb 2016 22:12:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUn7C-0000IU-WB for bug-grep@gnu.org; Sat, 13 Feb 2016 22:12:54 -0500 Received: from mail.spocom.com ([206.63.224.240]:60874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUn7C-0000Hq-MN for bug-grep@gnu.org; Sat, 13 Feb 2016 22:12:50 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; q=dns; d=spocom.com; s=mail; h=received:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-type:content-disposition :in-reply-to:x-operating-system:user-agent; b=0s1Fdk8OsvG21sOoc+6jmF2O0NsVNBl60BbDl62TvRrJjvGtz4ejsiSQeWYJ9ulc1 qjEgn0n+o9cECFf/TPvTg== Received: from localhost (97-115-178-104.spkn.qwest.net [97.115.178.104]) by mail.spocom.com with SMTP; Sat, 13 Feb 2016 18:27:00 -0800 Date: Sat, 13 Feb 2016 18:28:37 -0800 From: Gary Johnson To: bug-grep@gnu.org Subject: Re: bug#22656: How to grep two patterns in a line with correct coloring? Message-ID: <20160214022837.GA661@phoenix> Mail-Followup-To: bug-grep@gnu.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux 2.6.32-74-generic GNU/Linux User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 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 (----) 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 From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 11 00:45:57 2016 Received: (at 22656-done) by debbugs.gnu.org; 11 Apr 2016 04:45:57 +0000 Received: from localhost ([127.0.0.1]:57823 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1apTjY-0003Mc-Ta for submit@debbugs.gnu.org; Mon, 11 Apr 2016 00:45:57 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:34024) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1apTjX-0003MM-Lo for 22656-done@debbugs.gnu.org; Mon, 11 Apr 2016 00:45:55 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 4F64F160FD3; Sun, 10 Apr 2016 21:45:50 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id c7pr2kKXJ6f3; Sun, 10 Apr 2016 21:45:49 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id AF81C161250; Sun, 10 Apr 2016 21:45:49 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id KwJ9MA7HvlAk; Sun, 10 Apr 2016 21:45:49 -0700 (PDT) Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 91E2B160FD3; Sun, 10 Apr 2016 21:45:49 -0700 (PDT) To: Peng Yu From: Paul Eggert Subject: Re: How to grep two patterns in a line with correct coloring? Organization: UCLA Computer Science Department Message-ID: <570B2BFD.8010406@cs.ucla.edu> Date: Sun, 10 Apr 2016 21:45:49 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.0 (-) X-Debbugs-Envelope-To: 22656-done Cc: 22656-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: -1.0 (-) This works for me: grep --color=always -E 'word1|word2' From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 11 01:39:07 2016 Received: (at 22656) by debbugs.gnu.org; 11 Apr 2016 05:39:07 +0000 Received: from localhost ([127.0.0.1]:57869 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1apUZ1-00088b-IM for submit@debbugs.gnu.org; Mon, 11 Apr 2016 01:39:07 -0400 Received: from thorn.bewilderbeest.net ([71.19.156.171]:36679) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1apUYz-00088T-2B for 22656@debbugs.gnu.org; Mon, 11 Apr 2016 01:39:05 -0400 Received: from hatter.bewilderbeest.net (hatter.bewilderbeest.net [IPv6:2001:470:c3f4:1::1:1]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 63C7B8042E; Sun, 10 Apr 2016 22:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1460353143; bh=GpqxkEy4LFtt2WCg3DUbKoZ/geuO9cc4xSQfZrpA9b4=; h=Date:From:To:Subject:References:In-Reply-To:From; b=JmUr51lNI2QlPTabj/64pzrXUdh5/ZEtTygs8NQwvdgFk27jU0NCigGzMEjGBxd2H 3aKYFyxgQWVZ9Z7bJX+HIzibMv1DgPC2wNT3T3uhx4GV+sRGYjle1jxyBSSMMc3M1v OFUQBvDvcRP31lP3uFMzh32YecKSu6neqYhaEXFY= Date: Mon, 11 Apr 2016 00:39:00 -0500 From: Zev Weiss To: 22656@debbugs.gnu.org, eggert@cs.ucla.edu, pengyu.ut@gmail.com Subject: Re: bug#22656: How to grep two patterns in a line with correct coloring? Message-ID: <20160411053859.GB23038@hatter.bewilderbeest.net> References: <570B2BFD.8010406@cs.ucla.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <570B2BFD.8010406@cs.ucla.edu> User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Score: -1.0 (-) X-Debbugs-Envelope-To: 22656 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: -1.0 (-) 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 From debbugs-submit-bounces@debbugs.gnu.org Mon Apr 11 01:54:29 2016 Received: (at 22656) by debbugs.gnu.org; 11 Apr 2016 05:54:29 +0000 Received: from localhost ([127.0.0.1]:57882 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1apUnt-0008UU-9k for submit@debbugs.gnu.org; Mon, 11 Apr 2016 01:54:29 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:36817) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1apUns-0008UI-BO for 22656@debbugs.gnu.org; Mon, 11 Apr 2016 01:54:28 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id EE661161257; Sun, 10 Apr 2016 22:54:22 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id L_zLm1IzarrX; Sun, 10 Apr 2016 22:54:22 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 200D316125F; Sun, 10 Apr 2016 22:54:22 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id LxSlrTHQcXl1; Sun, 10 Apr 2016 22:54:22 -0700 (PDT) Received: from [192.168.1.9] (unknown [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id F014C161257; Sun, 10 Apr 2016 22:54:21 -0700 (PDT) Subject: Re: bug#22656: How to grep two patterns in a line with correct coloring? To: Zev Weiss , 22656@debbugs.gnu.org, pengyu.ut@gmail.com References: <570B2BFD.8010406@cs.ucla.edu> <20160411053859.GB23038@hatter.bewilderbeest.net> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <570B3C0D.2010201@cs.ucla.edu> Date: Sun, 10 Apr 2016 22:54:21 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20160411053859.GB23038@hatter.bewilderbeest.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.0 (-) X-Debbugs-Envelope-To: 22656 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: -1.0 (-) 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.... From unknown Wed Aug 20 05:18:08 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 09 May 2016 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