beyondgrep / ack2

**ack 2 is no longer being maintained. ack 3 is the latest version.**
https://github.com/beyondgrep/ack3/
Other
1.48k stars 138 forks source link

Pattern starting with a ^ (beginning of line) doesn't work when --files-with-matches option is used unless match is on first line #538

Closed GordanV closed 4 years ago

GordanV commented 9 years ago

I have found that the a regex beginning with a caret that finds matches in a file doesn't list the files found when the -l / --files-with-matches option is used unless the match occurs in the first line.

Steps to reproduce:

  1. Create testfile: echo -n "Don't Match this line\n but this one" > ack_testfile
  2. Find matches with ack: ack --noenv '^\s+' ack_testfile
    • Actual result: but this one
  3. Find filenames containing matches: ack --noenv -l '^\s+' ack_testfile
    • Expected result: ack_testfile
    • Actual result is empty

If I search for "^Don't" the -l option works as expected.

It seems like the meaning of ^ changes from 'beginning of line' to 'beginning of file' when the the -l option is used.

This should either be mentioned in the man page (or maybe a warning should be displayed when using that option) or preferably ack should behave the same with and without those options (-L / --files-without-matches is also affected).

hoelzro commented 9 years ago

This does occur on 2.14, but is fixed in the dev branch.

hoelzro commented 9 years ago

I do, however, see this probably with -L! Great catch!

GordanV commented 9 years ago

Great to hear and thanks for the quick reply!

petdance commented 4 years ago

This is good in ack 3.