Ripgrep: Feature request: --files-without-matches

0

One flag that occasionally comes useful is to identify files that _don't_ match a certain expression. Both ag and ack have -L/--files-without-matches (effectively the opposite of -l/--files-with-matches).

One minor problem here is that rg -L is already taken for following symlinks.

Curiously, ag -lv appears to be a synonym of -L. I'm not sure whether this is intentional or not, but it seems like a perfectly reasonable approach to me — in fact, years ago, before I knew of -L, this is actually what I first tried with ack, and got bogus results (it interprets this combo as "list all files that have at least one line that does not match the given expression", like ripgrep does today). Personally, I don't think I've ever had a use case for this.

mernen picture mernen  ·  30 Sep 2016

Most helpful comment

23

(If, like me, you're coming here from Google, the flag that made it into ripgrep is --files-without-match)

hauntsaninja picture hauntsaninja  ·  30 Jan 2020

All comments

1

I'm not opposed to adding --files-without-matches, but I don't think we need to add a short alias for it. I'd at least like to keep -L for following symlinks.

I'm also not opposed to making -v a bit smarter with respect to whether -l is given or not, but I worry that it will make "find files with a line that doesn't match" impossible to do.

BurntSushi picture BurntSushi  ·  30 Sep 2016
0

Ha, I almost added this earlier @mernen but ran into exactly the problem you described 😄

andschwa picture andschwa  ·  18 Oct 2016
0

OK, so I did some more thinking about this and I think the _current_ behavior of -lv is probably the right one. I totally get that it can be confusing, but -v pretty solidly refers to matching at the line level and isn't a generic "do the opposite" flag. In particular, grep -lv behaves the same as rg -lv.

Here is a proposed specification.

Add a new flag --files-without-matches. Only show the path of each file that contains zero matches.

BurntSushi picture BurntSushi  ·  19 Nov 2016
23

(If, like me, you're coming here from Google, the flag that made it into ripgrep is --files-without-match)

hauntsaninja picture hauntsaninja  ·  30 Jan 2020