Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you exclude a specific file from ack (ack-grep)?

Tags:

ack

With the normal grep command there is an --exclude option (covered in detail here: Use grep --exclude/--include syntax to not grep through certain files) that lets you ignore specific files when you are grepping.

Ack's --type option takes care of 95% of the cases where you'd want to exclude files, but it doesn't (as far as I can tell) handle the case of excluding a specific file. I've got a compiled JS file that has the contents of every other JS file in it (on a single line), so every time I grep for anything I get back the entire contents of that giant compiled file.

I'd hate to have to give up on ack and go back to grep over this, but it is really annoying. Please, someone tell me there's a way to exclude specific files from ack searches.

like image 981
machineghost Avatar asked Jul 24 '12 17:07

machineghost


People also ask

How do I exclude a file type in grep?

To read a list of files to exclude from a file, use --exclude-from FILE .

What is ACK grep?

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-grep prints the matching lines. PATTERN is a Perl regular expression.

What is ACK Ubuntu?

DESCRIPTION. ack is designed as an alternative to grep for programmers. ack searches the named input files or directories for lines containing a match to the given PATTERN. By default, ack prints the matching lines. If no FILE or DIRECTORY is given, the current directory will be searched.


2 Answers

To ignore a single file using ack 2.0, provide a filter spec to the --ignore-file flag:

--ignore-file=is:cljout.js

like image 182
jbouwman Avatar answered Oct 02 '22 12:10

jbouwman


If you run ack --create-ackrc it will output a whole bunch of presets for common files like minified javascript, css and directories like node_modules and .git. Very useful!

Here's the minified js option:

# minified Javascript --ignore-file=match:/[.-]min[.]js$/ --ignore-file=match:/[.]js[.]min$ 

And here's how to ignore a directory called foo:

--ignore-directory=is:foo 

If you want to save this to .ackrc run

ack --create-ackrc >> ~/.ackrc 

and then delete what you don't need from that file.

Also, you can create another .ackrc file in your project's root folder for project specific stuff. I put that in .gitignore so it doesn't clutter the repo.

like image 25
Rimian Avatar answered Oct 02 '22 12:10

Rimian