Monday, September 10, 2012

ack: Exclude search directories via regex - from Stack Overflow

OK, the hints shown at the bottom worked pretty well for me.  I wanted to find a certain string in C source files, but not be distracted by compiled release directories named "rel*".  I guessed at which wildcard syntax ack supports, and I think I won:

(cd ~/Work/mse1/compiler; ack -G 'rel*' --invert-file-match --type=cc -- "builtin_object_size" )

YMMV.  No warranties expressed or implied.  Thank god for undocumented/lightly documented features...  ;-)
Cheers,
Connie
----------------------------------------
Stack Overflow:
"
How do I ignore specific directories via RegEx with ack?
I can use the --ignore-dir option, but this does not let me specify a RegEx. I want to be able to ignore any directory, which has the words test or tests or more complicated patterns in its name.
I also tried a negative lookbehind via
ack -G '(? pattern
but this does not work. It does not exclude the test directories.
share|edit

feedback

2 Answers


Use the undocumented option "--invert-file-match" (ack version on my system: 1.96):
$ ack pattern -G 'test|tests' --invert-file-match
Well, it is sort of documented:
$ ack --help|grep invert-v, --invert-match    Invert match: select non-matching lines--invert-file-match   Print/search handle files that do not match -g/-G.
It is not documented in its perldoc.
share|edit
 "
ack: Exclude specific directories from search via regex - Stack Overflow

'via Blog this'

No comments:

Post a Comment