Ack

What is ack?

ack is a wonderful replacement for grep.

How can we install ack if we want to use it inside Git Bash?

mkdir ~/bin
curl https://beyondgrep.com/ack-2.22-single-file > ~/bin/ack && chmod 0755 ~/bin/ack

What are available options?

  1. -i ( --ignore-case )
  2. -v ( --invert-match ): select non-matching lines
  3. -w ( --word-regexp ): Force pattern to match only whole words
  4. -Q ( --literal ): Quote all metacharacters: pattern is literal
  5. --lines=NUM : Only print NUM lines of each file

See https://kapeli.com/cheat_sheets/Ack.docset/Contents/Resources/Documents/index

How can we tell ack to print only the name of the files that match our search pattern?

Use the -l switch:

ack -l

See https://serverfault.com/questions/57321/how-do-i-show-filenames-only-after-a-keyword-grep-search

My .ackrc file:

--type-add=php=.tpl
--ignore-dir=external
#make sure ack knows how to search common filetypes used in rails projects
--type-add=css=scss
--type-add=ruby=.haml,.rselm,.feature,.ru,.lock
--type-set=coffeescript=.coffee
--type-set=coffee=.coffee

#make sure ack knows how to search common filetypes used in node.js projects
--ignore-dir=node_modules
--type-set=coffee=.coffee
--type-set=jade=.jade
--type-set=feature=.feature
--type-set=json=.json

Can we have per directory or per project .ackrc file?

Yes. We can have per directory or per project .ackrc by putting:

export ACKRC=".ackrc"

into your .bashrc or .bash_profile file.

How can we tell ack to ignore the .ackrc file?

If we want to ignore the .ackrc file with the —noenv option:

ack --noenv pattern

http://beyondgrep.com/documentation/

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License