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

Previous Next

Package: grep;

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

Date: Fri, 29 Mar 2019 20:48:02 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: "Paul Jackson" <pj <at> usa.net>
To: 35043 <at> debbugs.gnu.org
Subject: bug#35043: Is there a way to show file name once just before all the	matches in the file?
Date: Fri, 29 Mar 2019 23:01:48 -0400
[Message part 1 (text/plain, inline)]
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 <at> usa.net
[Message part 2 (text/html, inline)]

This bug report was last modified 5 years and 166 days ago.

Previous Next


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