GNU bug report logs -
#28081
way to change line number separator from colon to space?
Previous Next
To reply to this bug, email your comments to 28081 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-grep <at> gnu.org
:
bug#28081
; Package
grep
.
(Sun, 13 Aug 2017 18:24:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Marcel Partap <mpartap <at> gmx.net>
:
New bug report received and forwarded. Copy sent to
bug-grep <at> gnu.org
.
(Sun, 13 Aug 2017 18:24:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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
Information forwarded
to
bug-grep <at> gnu.org
:
bug#28081
; Package
grep
.
(Sun, 13 Aug 2017 18:43:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 28081 <at> debbugs.gnu.org (full text, mbox):
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
Information forwarded
to
bug-grep <at> gnu.org
:
bug#28081
; Package
grep
.
(Sun, 13 Aug 2017 18:47:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 28081 <at> debbugs.gnu.org (full text, mbox):
> One way:
> grep <arguments> | sed "s/:/ /"
Thanks, obvious approach, but loses colour 😁
Information forwarded
to
bug-grep <at> gnu.org
:
bug#28081
; Package
grep
.
(Sun, 13 Aug 2017 19:06:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 28081 <at> debbugs.gnu.org (full text, mbox):
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
Severity set to 'wishlist' from 'normal'
Request was from
Paul Eggert <eggert <at> cs.ucla.edu>
to
control <at> debbugs.gnu.org
.
(Tue, 31 Dec 2019 19:37:02 GMT)
Full text and
rfc822 format available.
This bug report was last modified 5 years and 227 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.