GNU bug report logs - #35043
Is there a way to show file name once just before all the matches in the file?

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: grep; Severity: wishlist; Reported by: Peng Yu <pengyu.ut@HIDDEN>; dated Fri, 29 Mar 2019 20:48:02 UTC; Maintainer for grep is bug-grep@HIDDEN.
Severity set to 'wishlist' from 'normal' Request was from Paul Eggert <eggert@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 30 Mar 2019 03:02:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 29 23:02:10 2019
Received: from localhost ([127.0.0.1]:36129 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1hA4G2-0006pE-Gu
	for submit <at> debbugs.gnu.org; Fri, 29 Mar 2019 23:02:10 -0400
Received: from eggs.gnu.org ([209.51.188.92]:60275)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pj@HIDDEN>) id 1hA4G0-0006kO-LB
 for submit <at> debbugs.gnu.org; Fri, 29 Mar 2019 23:02:08 -0400
Received: from lists.gnu.org ([209.51.188.17]:50158)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <pj@HIDDEN>) id 1hA4Ft-0005PT-CV
 for submit <at> debbugs.gnu.org; Fri, 29 Mar 2019 23:02:02 -0400
Received: from eggs.gnu.org ([209.51.188.92]:46416)
 by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <pj@HIDDEN>)
 id 1hA4Fk-0001Ug-On
 for bug-grep@HIDDEN; Fri, 29 Mar 2019 23:01:56 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_50,HTML_MESSAGE,
 RCVD_IN_DNSWL_LOW,URIBL_BLOCKED autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <pj@HIDDEN>) id 1hA4Fj-0005M1-R6
 for bug-grep@HIDDEN; Fri, 29 Mar 2019 23:01:52 -0400
Received: from out4-smtp.messagingengine.com ([66.111.4.28]:40339)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <pj@HIDDEN>) id 1hA4Fj-0005LP-Kq
 for bug-grep@HIDDEN; Fri, 29 Mar 2019 23:01:51 -0400
Received: from compute1.internal (compute1.nyi.internal [10.202.2.41])
 by mailout.nyi.internal (Postfix) with ESMTP id 1AD6C21EF8
 for <bug-grep@HIDDEN>; Fri, 29 Mar 2019 23:01:50 -0400 (EDT)
Received: from imap28 ([10.202.2.78])
 by compute1.internal (MEProxy); Fri, 29 Mar 2019 23:01:50 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=content-type:date:from:in-reply-to
 :message-id:mime-version:references:subject:to:x-me-proxy
 :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=IKfZ3e
 WQGLvMtuKUE5mBDBEmQPkihoW3qBtfblLaDmI=; b=zoj3lS2R6G3j1F/n7kYPDJ
 Lt6zrn6r7hvlwB5jZNBHU7KWD9tVZUNAAz0Hb4rHXi7U87GoZHslsIq3O2QscxXp
 NcIXFMqKk+xTTT4VeJecgg7tdNjpjXpuTLx32fcFxXhkWcqkD5Gpmxfw+wMG0YQ2
 s3xf6QPG1iUvFhWTmquww1sQeuyKTQywkhJdv0C1YC88ZXc9hDj0QDn4zgYorK8X
 VkA8noCXmRBhZrhgcGO6Fr5xOztkTtpDWfbNLhr9GQRfS12fh4j+p+890ER6vTAB
 K42gJfmQux04meeWtC2kMIXiUTc1BJYazJVAtwgmeW4GyYyCWOP9nlEAmyj6mQxw
 ==
X-ME-Sender: <xms:HdyeXA89j-ZSnIOeYS9HvEcLwap9D2GbtJZxfJkX_FeERcsU720Htw>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrkeekgdehfecutefuodetggdotefrodftvf
 curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu
 uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesrgdtre
 erreerjeenucfhrhhomhepfdfrrghulhculfgrtghkshhonhdfuceophhjsehushgrrdhn
 vghtqeenucfrrghrrghmpehmrghilhhfrhhomhepphhjsehushgrrdhnvghtnecuvehluh
 hsthgvrhfuihiivgeptd
X-ME-Proxy: <xmx:HdyeXPPuOBkM7Y34RmltpcrehCA7MrTpdBV_omvLwIUkkqfgMJR6Aw>
 <xmx:HdyeXJOw7ETvS56-G8XUNm61Id3Rlh3hOkbPCap8-iVLZzzVsQxCig>
 <xmx:HdyeXKfVT3--Db1YumcKgEiRLFHbI0DQxO5ih52xCPHY_JA2fd5JDw>
 <xmx:HtyeXE7DpYvZb-V0-teP1PFF1RI4YlqT8IX8sDaf0z3j2hvVkP24rw>
Received: by mailuser.nyi.internal (Postfix, from userid 501)
 id 713354E636; Fri, 29 Mar 2019 23:01:49 -0400 (EDT)
X-Mailer: MessagingEngine.com Webmail Interface
User-Agent: Cyrus-JMAP/3.1.6-329-gf4aae99-fmstable-20190329v1
Mime-Version: 1.0
X-Me-Personality: 78241
Message-Id: <0f7c5c36-a0ed-4437-908b-09d0c69d78d6@HIDDEN>
In-Reply-To: <CABrM6wmR1PHTS1AAndzu1MBg6wv7985jythAbuBURgky-92opQ@HIDDEN>
References: <CABrM6wmR1PHTS1AAndzu1MBg6wv7985jythAbuBURgky-92opQ@HIDDEN>
Date: Fri, 29 Mar 2019 23:01:48 -0400
From: "Paul Jackson" <pj@HIDDEN>
To: bug-grep@HIDDEN
Subject: =?UTF-8?Q?Re:_bug#35043:_Is_there_a_way_to_show_file_name_once_just_befo?=
 =?UTF-8?Q?re_all_the=09matches_in_the_file=3F?=
Content-Type: multipart/alternative; boundary=fe1641a6dbed4bfbbb343f0f8ed60b71
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 66.111.4.28
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Spam-Score: 0.7 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.3 (/)

--fe1641a6dbed4bfbbb343f0f8ed60b71
Content-Type: text/plain


The following awk command will do this (so long as filenames don't have ':' colon chars):

grep IP /etc/protocols /etc/services |
 awk -F: '
 $1 != fname { print $1 ":"; fname = $1; }
 { sub("^[^:]*:", ""); print; }
 '

-- 
 Paul Jackson
 pj@HIDDEN
--fe1641a6dbed4bfbbb343f0f8ed60b71
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html><html><head><title></title><style type=3D"text/css">p.Mso=
Normal,p.MsoNoSpacing{margin:0}</style></head><body><div style=3D"font-f=
amily:Arial;"><br></div><div style=3D"font-family:Arial;">The following =
awk command will do this (so long as filenames don't have ':' colon char=
s):<br></div><div style=3D"font-family:Arial;"><br></div><div style=3D"f=
ont-family:Arial;"><span style=3D"font-family: menlo, consolas, monospac=
e, sans-serif;" class=3D"font">grep IP /etc/protocols /etc/services |</s=
pan><span style=3D"font-family: menlo, consolas, monospace, sans-serif;"=
 class=3D"font"><br></span></div><div style=3D"font-family:Arial;"><span=
 style=3D"font-family: menlo, consolas, monospace, sans-serif;" class=3D=
"font">&nbsp;&nbsp;&nbsp; awk -F: '</span><span style=3D"font-family: me=
nlo, consolas, monospace, sans-serif;" class=3D"font"><br></span></div><=
div style=3D"font-family:Arial;"><span style=3D"font-family: menlo, cons=
olas, monospace, sans-serif;" class=3D"font">&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; $1 !=3D fname { print $1 ":"; fname =3D $1; }</span><spa=
n style=3D"font-family: menlo, consolas, monospace, sans-serif;" class=3D=
"font"><br></span></div><div style=3D"font-family:Arial;"><span style=3D=
"font-family: menlo, consolas, monospace, sans-serif;" class=3D"font">&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { sub("^[^:]*:", ""); print; }<=
/span><span style=3D"font-family: menlo, consolas, monospace, sans-serif=
;" class=3D"font"><br></span></div><div style=3D"font-family:Arial;"><sp=
an style=3D"font-family: menlo, consolas, monospace, sans-serif;" class=3D=
"font">&nbsp;&nbsp;&nbsp; '</span><span style=3D"font-family: menlo, con=
solas, monospace, sans-serif;" class=3D"font"><br></span></div><div styl=
e=3D"font-family:Arial;"><br></div><div style=3D"font-family:Arial;">--&=
nbsp;<br></div><div style=3D"font-family:Arial;">&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Paul=
 Jackson<br></div><div style=3D"font-family:Arial;">&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p=
j@HIDDEN<br></div></body></html>
--fe1641a6dbed4bfbbb343f0f8ed60b71--




Information forwarded to bug-grep@HIDDEN:
bug#35043; Package grep. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 29 Mar 2019 20:47:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Mar 29 16:47:55 2019
Received: from localhost ([127.0.0.1]:36052 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1h9yPq-0002YC-Pi
	for submit <at> debbugs.gnu.org; Fri, 29 Mar 2019 16:47:54 -0400
Received: from eggs.gnu.org ([209.51.188.92]:33551)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pengyu.ut@HIDDEN>) id 1h9yPo-0002Xz-QG
 for submit <at> debbugs.gnu.org; Fri, 29 Mar 2019 16:47:53 -0400
Received: from lists.gnu.org ([209.51.188.17]:49729)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <pengyu.ut@HIDDEN>) id 1h9yPj-0003FF-Je
 for submit <at> debbugs.gnu.org; Fri, 29 Mar 2019 16:47:47 -0400
Received: from eggs.gnu.org ([209.51.188.92]:47928)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <pengyu.ut@HIDDEN>) id 1h9yPi-0003pI-Nd
 for bug-grep@HIDDEN; Fri, 29 Mar 2019 16:47:47 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM
 autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <pengyu.ut@HIDDEN>) id 1h9yPg-0003EH-Pj
 for bug-grep@HIDDEN; Fri, 29 Mar 2019 16:47:46 -0400
Received: from mail-it1-x12b.google.com ([2607:f8b0:4864:20::12b]:54911)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <pengyu.ut@HIDDEN>) id 1h9yPg-0003D9-IG
 for bug-grep@HIDDEN; Fri, 29 Mar 2019 16:47:44 -0400
Received: by mail-it1-x12b.google.com with SMTP id w18so5907574itj.4
 for <bug-grep@HIDDEN>; Fri, 29 Mar 2019 13:47:43 -0700 (PDT)
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=cp+BiLX/3O7v9O/qzPsFIN3LoULM4/EypSbck0n6zeY=;
 b=G4QuQgAYgx6tEVPDdB2gOCG+F302nUuUp+MM6toaBzN77QcgxyxREFClXaSllSUvbj
 3pjERBOivav2F/OBBgh5M/tUukjWftzkXxNuU7VzL8k/chI7YHc6Yk3T42NWn1pofC3a
 /+faLwTCFTm3NCJQYVc8tJKRYVIcyOUgZudYQXBUCWDvM2b1aGEijX4eXxKkX0UOejrz
 UJsOVG+BP6E0qxqXWsUx0/89PVguYuJy2AoGbUsmtCEj9AmrBjrAsu6dX9HSMX58RQC1
 4nerg9j3uUZBCI2Vf2nLAbgTJwpQBb4DXoNTcIXsY4xPWmwWRQnLJIG/ycL/ONAeZUCR
 Q2zw==
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=cp+BiLX/3O7v9O/qzPsFIN3LoULM4/EypSbck0n6zeY=;
 b=No65TZ7akrgYTdVIAQBKD+oILa7p4CHxTZ8YbEpB7EMvl714FsAU8vKZv2SmY0tkmy
 1l3F7Q7v/3U9aglWBihVVWojSzCN4a9pLVGJJvJ0sjGT80n+4XOj7bb7ugsHoVE+ItFE
 nfQNe2DVL0eHqMmMP9lL2FeJ5BbZfhxQUvgcbQYcAgQtJj1Zeh58AWqjpWNNQis/fnC4
 P9/O/sUC/ZVsDRH3DNN9LxFicOMnTXr7osLQCJg5lWRL/Dqo2jEg0HnCPktJ+1mzG00m
 f9jTBipLP8Y8s05McNBKZ7XEH+nwytMGziSizM1u56FyA1W+LvhUXwD1ZCpe7t2yf9Xb
 3TRQ==
X-Gm-Message-State: APjAAAXexxUlh5VVdoTvfJj7jdd05Ya2pWDGSd1sanVkLdfmMl/64t9D
 ZmD4C6ton8dJ+Yidc1NfGZlfMNPq9tIp0JjwO7dpZw==
X-Google-Smtp-Source: APXvYqy9yi+vfxMKp2PPcUCWhqRsneEq8tLCIVx16rWXJxVnWexkR5dDG/r1nSvcpt7UZ1fk1hzTASG0dbeEhs8WO/8=
X-Received: by 2002:a24:57c1:: with SMTP id u184mr6209313ita.38.1553892462755; 
 Fri, 29 Mar 2019 13:47:42 -0700 (PDT)
MIME-Version: 1.0
Received: by 2002:a5e:9707:0:0:0:0:0 with HTTP; Fri, 29 Mar 2019 13:47:41
 -0700 (PDT)
From: Peng Yu <pengyu.ut@HIDDEN>
Date: Fri, 29 Mar 2019 15:47:41 -0500
Message-ID: <CABrM6wmR1PHTS1AAndzu1MBg6wv7985jythAbuBURgky-92opQ@HIDDEN>
Subject: Is there a way to show file name once just before all the matches in
 the file?
To: bug-grep@HIDDEN
Content-Type: text/plain; charset="UTF-8"
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2607:f8b0:4864:20::12b
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

Hi,

By default, filenames are shown at the same lines of the matches (when
there are multiple files). But I'd like a filename only shown once
before all the matches in the given file. Is there an option to do so
with grep? Thanks.

-- 
Regards,
Peng




Acknowledgement sent to Peng Yu <pengyu.ut@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-grep@HIDDEN. Full text available.
Report forwarded to bug-grep@HIDDEN:
bug#35043; Package grep. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 2 Jan 2020 09:30:02 UTC

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