Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search for a specific file type with ack

Tags:

How can I use ack to search in files of a specific file type.

For example

ack -f .scss blah acl -f .rb blah 

Obviously the above does not work but how can I do this with ack?

like image 622
dagda1 Avatar asked Aug 08 '14 09:08

dagda1


People also ask

How do I search for a specific file format?

You can use the filetype: operator in Google Search to limit results to a specific file type. For example, filetype:rtf galway will search for RTF files with the term "galway" in them.

What is the ACK command in Linux?

Description. Ack is designed as a replacement for 99% of the uses of grep. Ack searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN . By default, ack prints the matching lines.

What is ACK file format?

What is ACK file? Full format name of files that use ACK extension is Swifty. ACK file format is compatible with software that can be installed on Windows system platform. Files with ACK extension are categorized as Misc Files files. The Misc Files subset comprises 6033 various file formats.


2 Answers

Use --type for this. To only search python files for example:

ack --type=python searchthis 

List all the supported types with

ack --help=types  # ack 2.x ack --help-types  # ack 3.x.x 

If you want to create a custom type, add something like this to ~/.ackrc:

--type-add=custom:ext:rb --type-set 

Then you can use --type=custom with ack to just search file with the .rb extension.

like image 97
Leon Avatar answered Oct 12 '22 15:10

Leon


find . -name '*.scss' | ack -x 'blah' 

-x Read the list of files to search from STDIN.

like image 36
Joe Avatar answered Oct 12 '22 14:10

Joe