ack is a fantastic tool to do recursive searches in text files, such as in your source code. It is simple to use and amazingly fast. See the ack home page for installation instructions. I am on OS X without Macport and installed ack with:
sudo perl -MCPAN -e 'install App::Ack'
- Ignoring certain files
gaga.js) I have a minimized version of that file (
gaga-min.js) automatically generated for me. I am never interested in searching in those files. ack doesn't have an option for you to say which files you want to ignore, but you can specify what files you want it to include:
-G. This option takes a Perl regular expression. How to write a regular expression that matches any file except those ending with
-min.js? With a negative look-behind regexp:
To have this used by default, add the following two lines to your
- Adding file types
- ack only search in files that are of a "type" it knows about. In general, files are mapped to types by extension, but in some cases they can be mapped by their content. I ran into a case where ack would find what I look for in certain
.xplfiles1, but not others. The reason was that ack didn't know about the
.xplextension, so it would ignore those files, except those that started with an XML declaration. For those files, even if it didn't recognize the extension, it would recognize the content and know it is dealing with an XML file.
If you run into a similar situation and suspect this is your problem, run the following command which will list the files ack will search in, starting from the current directory:
After you find which file are ignored, add those to your
ack -f .
.ackrcso ack recognizes those files. For instance, the following parameters added to your
.ackrcwill get ack to recognize
.xslfiles as XML files:
.xplare the pipeline files we use in Orbeon Forms.