Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ack to search inside files with no extensions

Tags:

grep

ack

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.

like image 536
Felix Avatar asked Oct 15 '25 08:10

Felix


2 Answers

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
like image 109
Hong Avatar answered Oct 16 '25 21:10

Hong


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.

like image 32
James Aylett Avatar answered Oct 16 '25 22:10

James Aylett