the_silver_searcher: --files-without-matches does not work properly

-l and -L should be mutually exclusive, but they are not.

A simple example illustrating the issue:

zsh 12550 % echo test123 > file
zsh 12551 % ag -L test file 
file
zsh 12552 % ag -l test file
file
zsh 12548 % ag --version
ag version 0.15

About this issue

  • Original URL
  • State: open
  • Created 11 years ago
  • Reactions: 2
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Any updates on this? -L completely ignores matches on the first line of the file. Seems like if this isn’t going to be fixed soon, the flag should be removed entirely, as it effectively does not work as advertised at all.

I believe this issue should be closed, as a dupe of many other issues, because it should be fixed once and for all by #1245, which has been merged for some months now. /cc @ggreer

Still an issue… I spent 30 minutes trying to understand why a file was showing in both ag -l and ag -L

$ ag --version
ag version 2.2.0

Features:
  +jit +lzma +zlib

$ echo -e "foo\nbar" > file.txt

$ cat file.txt
foo
bar

$ ag --files-with-matches bar file.txt
file.txt

$ ag --files-without-matches bar file.txt
file.txt

$ echo "" >> file.txt

$ cat file.txt
foo
bar


$ ag --files-with-matches bar file.txt
file.txt

$ ag --files-without-matches bar file.txt
# No result

Looks like ag -L ignores a file’s last line. grep gets it right:

$ grep --version
grep (GNU grep) 3.1
Packaged by Homebrew
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

$ echo -e "foo\nbar" > file.txt

$ cat file.txt
foo
bar

$ grep -l bar file.txt
file.txt

$ grep -L bar file.txt
# No result

Still valid today. What was reported by @serhalp is still true.

It’s still an issue with current master (630125a). The issue seems to be that -L ignores matches on the first line of the file.

$ ./ag Silver
README.md
1:# The Silver Searcher

doc/ag.1.md
1:ag(1) -- The Silver Searcher. Like ack, but faster.

doc/ag.1
7:\fBag\fR \- The Silver Searcher\. Like ack, but faster\.

NOTICE
1:The Silver Searcher

the_silver_searcher.spec.in
19:The Silver Searcher