Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create an ack file type based on a filename, not extension?

Tags:

ack

I would like to include files with a specific name -- not an extension -- in my ack search. Is this possible with ack?

If I use the -G option, this would exclude all other file types. (So I can't put it in my .ackrc file.)

I tried to use --type-set mytype=filename.txt but this only works for extensions, so this would search for files including the pattern .filename.txt, thus not find filename.txt. (That's also what the ack --help types shows: --mytype .filename.txt, not --mytype filename.txt.)

Someone any ideas?

like image 798
Marvin Avatar asked Apr 07 '11 13:04

Marvin


3 Answers

man ack says that the files to be searched in can be given through standard input.
So this should work:

find . -name filename.txt | ack PATTERN -

Unfortunately, it doesn't. It gives ack: Ignoring 1 argument on the command-line while acting as a filter., which apparently is a bug in ack. When this bug will be fixed, we should be able to use

find . -name filename.txt | ack --nofilter PATTERN -

like image 80
Marvin Avatar answered Oct 16 '22 03:10

Marvin


You also do it like if you're using zsh:

ack 'Pattern' **/filename.txt

like image 30
iltempo Avatar answered Oct 16 '22 05:10

iltempo


What you're asking is "can I make a filetype that ack recognizes based on a filename", and the answer is "No, not in ack 1.x, but you can in ack 2.0". ack 2.0 is in alpha release, and we hope to have a beta by Christmas.

As @Christian pointed out above, you can specify the given filename on the command line, but that bypasses filetype checking entirely.

like image 20
Andy Lester Avatar answered Oct 16 '22 04:10

Andy Lester