3

I have some text "bar" contained in files FOO and foo.cc.

Is there a way to tell ack-grep to search inside files with no extension (namely FOO)?

I've tried something like this:

ack-grep --type-set=foo=FOO bar

which returns the text in foo.cc, but not file FOO.

I've also added the --type-set to my .ackrc file, calling

ack-grep --help-types

shows that ack-grep is looking for .FOO files.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
Felix
  • 2,064
  • 3
  • 21
  • 31

3 Answers3

2

You can combine ack-grep's -a (search everything) with -G (only search files that match a given regex). Something like:

ack-grep -a -G '^[^.]+$' what-to-search-for

should do the trick.

Under ack2 you have to define a custom type:

ack-grep --WANTED --type-set WANTED:match:^[^.]+$ what-to-search-for

works for me.

James Aylett
  • 3,332
  • 19
  • 20
  • 1
    This only works for ack 1.x. The `-a` and `-G` flags have been removed in ack 2.0 because they are no longer necessary. – Andy Lester Jul 20 '13 at 05:12
  • @AndyLester good point, thanks. Updated for ack2. (I'd argue that ack1 is more obvious in this case, but hey.) – James Aylett Jul 24 '13 at 20:10
2

My ack is of version 2.12. Bellow command should work.

$ ack --type-set make:is:Makefile --type=make string-pattern

So similarly,

$ ack --type-set foo:is:FOO --type=foo string-pattern
Hong
  • 1,203
  • 1
  • 13
  • 18
1

You cannot do what you want with ack 1.x. You need to upgrade to ack 2.0.

ack 1.x did not have a way to deal with files without extensions. ack 2.0 adds a much more flexible file-specification system.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152