git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git grep -F doesn't behave like grep -F?

From
TCTorne (Richard Coles) <torne@google.com>
Date
May 18, 2012, 12:41 UTC
Message-ID
<CAEV-rjd=WjLu8e+UCnAHVxg7DTLWe+YrEO_Gs2rh5Oy1=KA5sw@mail.gmail.com>
In-Reply-To
<4FB6426C.7040202@lsrfire.ath.cx>
On 18 May 2012 13:37, René Scharfe <rene.scharfe@lsrfire.ath.cx> wrote:
Show 19 quoted lines
> Am 18.05.2012 13:00, schrieb Torne (Richard Coles):
>
>> Hi folks,
>>
>> git grep -F is documented as: "Use fixed strings for patterns (don’t
>> interpret pattern as a regex)."
>>
>> whereas grep -F is documented as "Interpret PATTERN as a  list  of
>> fixed  strings,  separated  by newlines,  any  of  which is to be
>> matched."
>>
>> This accurately describes how they behave, which means that git grep
>> -F with a pattern containing newlines never matches anything (at least
>> as far as I can see). Is this intentional, or an oversight? The
>> ability to grep -F for a list (e.g. the output of another grep) is
>> pretty handy...
>
>
> You could use -f- (read patterns from stdin).
Ah, yes, rewriting
git grep -F "`git grep -o someregex`"
as
git grep -o someregex | git grep -F -f-
works, but it's not how I immediately think to do it :)
> That said, it looks like a missing feature to me -- at least I didn't know
> that grep -F takes newline separated lists of search strings.  And this
> doesn't seem to be restricted to invocations with -F, only; a plain grep
> with regexps does it as well.

Yeah, it doesn't seem like adding it would break anything; patterns with newlines don't match any lines by definition currently :)

-- 
Torne (Richard Coles)
torne@google.com
Previous: René ScharfeNext: René Scharfe
Message 3 of 8 in “git grep -F doesn't behave like grep -F?”
  1. Torne (Richard Coles)May 18, 2012
  2. René ScharfeMay 18, 2012
  3. Torne (Richard Coles)May 18, 2012
  4. 1/3 grep: factor out create_grep_pat()René Scharfe, May 20, 2012
  5. 2/3 grep: factor out do_append_grep_pat()René Scharfe, May 20, 2012
  6. 3/3 grep: support newline separated pattern listRené Scharfe, May 20, 2012
  7. Junio C HamanoMay 20, 2012
  8. René ScharfeMay 21, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.