# request: add git grep -o option

3 messages from 2019-10-30 to 2019-10-30. Participants: Joe Perches, Jeff King.
Thread: https://gitlist.dev/t/52162

## Joe Perches, 2019-10-30 19:58

Subject: request: add git grep -o option
Message-ID: <277ee7531df8dfd3249f189b9b298a5d187ec479.camel@perches.com>
URL: https://gitlist.dev/e/277ee7531df8dfd3249f189b9b298a5d187ec479.camel%40perches.com

```
Instead of duplicating a grep pattern with grep -oh after
git grep like
this:

$ git grep -P '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?' -- '*.[ch]' | \
  grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'

it could be useful to have git grep have the same '-o' option 
as gnu grep.



```

## Jeff King, 2019-10-30 20:17

Subject: Re: request: add git grep -o option
Message-ID: <20191030201757.GA29013@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20191030201757.GA29013%40sigill.intra.peff.net
In-Reply-To: <277ee7531df8dfd3249f189b9b298a5d187ec479.camel@perches.com>

```
On Wed, Oct 30, 2019 at 12:58:59PM -0700, Joe Perches wrote:

> Instead of duplicating a grep pattern with grep -oh after
> git grep like
> this:
> 
> $ git grep -P '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?' -- '*.[ch]' | \
>   grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'
> 
> it could be useful to have git grep have the same '-o' option 
> as gnu grep.

Doesn't it already?

  $ git grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'
  for_each
  for_each
  for_each_abbrev
  for_each_builtin
  for_each_string_list_item
  for_each_ut
  [etc...]

It was new in Git v2.19.

-Peff

```

## Joe Perches, 2019-10-30 20:27

Subject: Re: request: add git grep -o option
Message-ID: <d56bb5bcba50f1d9adf861b985a9646e7f65bdc9.camel@perches.com>
URL: https://gitlist.dev/e/d56bb5bcba50f1d9adf861b985a9646e7f65bdc9.camel%40perches.com
In-Reply-To: <20191030201757.GA29013@sigill.intra.peff.net>

```
On Wed, 2019-10-30 at 16:17 -0400, Jeff King wrote:
> On Wed, Oct 30, 2019 at 12:58:59PM -0700, Joe Perches wrote:
> 
> > Instead of duplicating a grep pattern with grep -oh after
> > git grep like
> > this:
> > 
> > $ git grep -P '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?' -- '*.[ch]' | \
> >   grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'
> > 
> > it could be useful to have git grep have the same '-o' option 
> > as gnu grep.
> 
> Doesn't it already?
> 
>   $ git grep -P -oh '(?:[a-z0-9_]+_)?for_each(?:_[a-z0-9_]+)?'
>   for_each
>   for_each
>   for_each_abbrev
>   for_each_builtin
>   for_each_string_list_item
>   for_each_ut
>   [etc...]
> 
> It was new in Git v2.19.

OK, nice.  I never actually tried it and I have 2.24.
My docs need updating as that option is not mentioned.



```
