threads / discuss / 15575

How to supply "raw" bytes to git grep?

Subject: How to supply "raw" bytes to git grep?

## tl;dr

5 messages between Sep 18, 2008 and Sep 18, 2008.

replies: 4people: 4as markdown or json

Johan Herland· Sep 18, 2008, 15:28 UTC · lore
Hi,

I wanted to list all text files in my repo which contain carriage returns, so I tried the following command-line:

	git grep --cached -I -l -e <CR>

where <CR> is some magic incantation that I've yet to figure out. I've tried all the obvious cases (\r, 0x0d, \015, etc.), but none of them seem to DWIM...

The only working solution I've found so far is to create a file (named "cr") in a hex editor that contains exactly one CR byte, and then use the -f option to 'git grep':

	git grep --cached -I -l -f cr

Is there an easier way? And if not, should I try to create one (e.g. teaching 'git grep' to grok backslash escapes)?

Have fun!
...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Jacob Helwig· Sep 18, 2008, 15:46 UTC · re: Johan Herland · lore

Re: How to supply "raw" bytes to git grep?

On Thu, Sep 18, 2008 at 08:28, Johan Herland <johan@herland.net> wrote:
Show 33 quoted lines
> Hi,
>
> I wanted to list all text files in my repo which contain carriage
> returns, so I tried the following command-line:
>
>        git grep --cached -I -l -e <CR>
>
> where <CR> is some magic incantation that I've yet to figure out. I've
> tried all the obvious cases (\r, 0x0d, \015, etc.), but none of them
> seem to DWIM...
>
> The only working solution I've found so far is to create a file
> (named "cr") in a hex editor that contains exactly one CR byte, and
> then use the -f option to 'git grep':
>
>        git grep --cached -I -l -f cr
>
> Is there an easier way? And if not, should I try to create one (e.g.
> teaching 'git grep' to grok backslash escapes)?
>
>
> Have fun!
>
> ...Johan
>
> --
> Johan Herland, <johan@herland.net>
> www.herland.net
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Inserting a literal carriage return seems to do the trick for me, in bash.
git grep --cached -I -l -e <Ctrl-V><Ctrl-M>
Johan Herland· Sep 18, 2008, 16:18 UTC · re: Jacob Helwig · lore

Re: How to supply "raw" bytes to git grep?

On Thursday 18 September 2008, Jacob Helwig wrote:
Show 14 quoted lines
> On Thu, Sep 18, 2008 at 08:28, Johan Herland wrote:
> > I wanted to list all text files in my repo which contain carriage
> > returns, so I tried the following command-line:
> >
> >        git grep --cached -I -l -e <CR>
> >
> > where <CR> is some magic incantation that I've yet to figure out.
> > I've tried all the obvious cases (\r, 0x0d, \015, etc.), but none
> > of them seem to DWIM...
>
> Inserting a literal carriage return seems to do the trick for me, in
> bash.
>
> git grep --cached -I -l -e <Ctrl-V><Ctrl-M>
Thanks. That's exactly the incantation I was looking for. ;)
...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Kalle Olavi Niemitalo· Sep 18, 2008, 22:07 UTC · re: Jacob Helwig · lore

Re: How to supply "raw" bytes to git grep?

"Jacob Helwig" <jacob.helwig@gmail.com> writes:
> Inserting a literal carriage return seems to do the trick for me, in bash.
>
> git grep --cached -I -l -e <Ctrl-V><Ctrl-M>

In bash, $'\r' works too, and may be nicer to edit. Better not use that with #! /bin/sh though.

Jakub Narebski· Sep 18, 2008, 16:31 UTC · re: Johan Herland · lore

Re: How to supply "raw" bytes to git grep?

Johan Herland wrote:
Show 8 quoted lines
> I wanted to list all text files in my repo which contain carriage 
> returns, so I tried the following command-line:
> 
>       git grep --cached -I -l -e <CR>
> 
> where <CR> is some magic incantation that I've yet to figure out. I've 
> tried all the obvious cases (\r, 0x0d, \015, etc.), but none of them 
> seem to DWIM...

Why not use _literal_ CR; of course protecting it by piockung it by shell as end of command by quites, for example

  $ git grep --cached -I -l -e '
  '
It works for me (bash).
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

← back to recent threads