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?
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.
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? 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.
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.
find . -name '*.scss' | ack -x 'blah'
-x Read the list of files to search from STDIN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With