Ack > Grep

Recently I’ve needed to do some string searches for occurrences on my local file system. I can tell you by far the easiest thing I’ve found to get up and running quickly is `ack` with a combination of other tools:

First off let’s start with a simple string search:

ack -io "my( | )simple( | )string( | )search" --ignore-dir={example,directories,to,ignore}

This does a couple things.

  1. -i means to ignore case, -o means output the line and occurrence of the string
  2. Everyhing in quotes is the regex (normal regex)
  3. ignore a list of directories (if it was a single directory don’t use curly braces.

The only wierdness is my regex which just looks for regular white spaces and nonbreaking characters as well. Ignore my regex and you get the basic structure:

ack -io "search string" --ignore-dir={ignore,these/directories}

If you want to see the entire line with the occurence you would just remove the -o value:

ack -i "search string" --ignore-dir={ignore,these/directories}

And that’s it! So simple you can’t afford not to try it out. If you’re on a mac, installation is simple:

brew install ack

One thought on “Ack > Grep

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.