Package: grep;
To reply to this bug, email your comments to 28081 AT debbugs.gnu.org.
the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
bug-grep <at> gnu.org:bug#28081; Package grep.
(2017年8月13日 18:24:02 GMT) Full text and rfc822 format available.Marcel Partap <mpartap <at> gmx.net>:bug-grep <at> gnu.org.
(2017年8月13日 18:24:02 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Marcel Partap <mpartap <at> gmx.net> To: bug-grep <at> gnu.org Subject: way to change line number separator from colon to space? Date: 2017年8月13日 15:41:19 +0200
Hi, is there any way to make grep place a space before and after the line number instead of a colon? > *./src/ui_download_manager.cc:36:namespace cwidget With many terminals not including the : as a word separator SHIFT+double click on the filename selects > filename:line: so one has to manually select the filename. So much unneccessary work 😁 #Best Regards/MPartap
bug-grep <at> gnu.org:bug#28081; Package grep.
(2017年8月13日 18:43:02 GMT) Full text and rfc822 format available.Message #8 received at 28081 <at> debbugs.gnu.org (full text, mbox):
From: Bruce Dubbs <bruce.dubbs <at> gmail.com> To: Marcel Partap <mpartap <at> gmx.net>, 28081 <at> debbugs.gnu.org Subject: Re: bug#28081: way to change line number separator from colon to space? Date: 2017年8月13日 13:42:40 -0500
Marcel Partap wrote: > Hi, > is there any way to make grep place a space before and after the line number instead of a colon? >> *./src/ui_download_manager.cc:36:namespace cwidget > With many terminals not including the : as a word separator SHIFT+double click on the filename selects >> filename:line: > so one has to manually select the filename. So much unneccessary work 😁 One way: grep <arguments> | sed "s/:/ /" You could easily create a script to automatically do that. It wouldn't handle the case where a colon is a part of the file name, but that's pretty rare. -- Bruce
bug-grep <at> gnu.org:bug#28081; Package grep.
(2017年8月13日 18:47:02 GMT) Full text and rfc822 format available.Message #11 received at 28081 <at> debbugs.gnu.org (full text, mbox):
From: Marcel Partap <mpartap <at> gmx.net> To: Bruce Dubbs <bruce.dubbs <at> gmail.com>, 28081 <at> debbugs.gnu.org Subject: Re: bug#28081: way to change line number separator from colon to space? Date: 2017年8月13日 20:45:58 +0200
> One way: > grep <arguments> | sed "s/:/ /" Thanks, obvious approach, but loses colour 😁
bug-grep <at> gnu.org:bug#28081; Package grep.
(2017年8月13日 19:06:02 GMT) Full text and rfc822 format available.Message #14 received at 28081 <at> debbugs.gnu.org (full text, mbox):
From: Assaf Gordon <assafgordon <at> gmail.com> To: Marcel Partap <mpartap <at> gmx.net>, Bruce Dubbs <bruce.dubbs <at> gmail.com>, 28081 <at> debbugs.gnu.org Subject: Re: bug#28081: way to change line number separator from colon to space? Date: 2017年8月13日 13:05:42 -0600
Hello,
On 13/08/17 12:45 PM, Marcel Partap wrote:
>> One way:
>> grep <arguments> | sed "s/:/ /"
> Thanks, obvious approach, but loses colour 😁
Few things:
First,
you can force grep to output color with:
grep --color=always <argument> | sed 's/:/ /'
Second,
If you grep on a shell-glob (e.g. "*.txt"),
you might want to add "-H -n" to force grep
to always output the filename and the line number.
Otherwise, if the glob matches a single file,
grep by default will not output the filename/line number -
and the 'sed' will not do what you wanted.
grep --color=always -Hn <argument> *.txt
Third,
This assumes filenames do not contain the character ':'
(which is probably a valid assumptions most of the time, but not always).
To be more robust, you can use GNU grep's "-Z" option, which outputs
a NUL after the filename, the GNU sed to replace the NUL with something
else.
Example:
$ grep --color=always -HZn Deb /etc/motd | sed 's/\x00/ === /'
/etc/motd === 2:The programs included with the Debian GNU/Linux
/etc/motd === 6:Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY
Fourth,
To easily automate all of that, you can create
a tiny shell function (put it in ~/.bashrc or ~/.bash_aliases, etc):
nicegrep() { grep --color=always -HZn "$@" | sed 's/\x00/ === /' ; }
Then run:
nicegrep Deb /etc/motd
regards,
- assaf
Paul Eggert <eggert <at> cs.ucla.edu>
to control <at> debbugs.gnu.org.
(2019年12月31日 19:37:02 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.