0

I am using ack and I want to avoid searching through any file which has name test. How do I do that?

Following ensures that only search through files or directory with name test. I want reverse of it.

ack foo --rb -G test
Nick Vanderbilt
  • 36,724
  • 29
  • 83
  • 106

1 Answers1

1
ack -G '^(?!test$)'
ack -G '^(?!.*test)'

Use the first one to ignore files named exactly test. Use the second to ignore files with the word test anywhere inside.

If you want to permanently ignore test files you could edit the is_searchable function in the ack script. This is the routine which filters out core dumps, swap files, and the like.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • why do I need the caret sign to make it work. Based on this http://www.rubular.com/ caret is only to signify start of line. – Nick Vanderbilt Apr 06 '11 at 21:01
  • You need to anchor the negative lookahead or else it will always match. If you just write `(?!test)` then that will match all file names because the lookahead will always be able to find *some* position where the word "test" does not exist. – John Kugelman Apr 06 '11 at 21:17