About

Welcome to Panela, Matt Harrison's take on mostly Open Source, Linux, Python, innovation in those areas, other buzzwords and Dick Proenneke. It comes complete with the illustrations as needed. Note the opinions expressed here are merely my opinions and not the opinions of my employer.

about Matt

Calendar

««Nov 2009»»
SMTWTFS
1234567
8910
11
12
1314
151617
18
192021
22232425262728
2930

Mailing List

My RSS Feeds








Programming tools I like - ack

posted 2008.12.17 Wed

No, that's not a misspelling in the title. I switched back to gentoo on my lappy, so while re-constructing my environment I found I forgot to install this swell little tool. I've been meaning to mention ack for a while. Ack is a nice little command line perl script, that describes itself "as a replacement for 99% of the uses of grep". If you find yourself typing anything similar to find . | xargs grep foo, you owe it to yourself to try ack, if you haven't already.

tags:      

links: digg this    del.icio.us    reddit




1. nat left...
2008.12.17 Wed 5:13 pm

or if you want something a little more python-y, grin is virtually identical. I don't actually know if there is any functional difference, but it can be easy_installed, and that's always nice.


2. Daniel Watkins left...
2008.12.17 Wed 7:52 pm :: http://blog.daniel-watkins.co.uk

While I appreciate that this isn't really the point of your post, 'grep foo -R .' does what your example does. Might be worth finding a more expressive/interesting example (and showing how ack does it better), because I haven't seen anything to make me check it out yet...


3. Dave Kirby left...
2008.12.18 Thu 12:59 am

Alternatively, you could switch from bash to zsh. This has superior filename expansion, including expanding through a directory tree. For example:

grep "regex" src/**/*.(c|h)

will recursively search for "regex" in all .c and .h files in the src tree. Since it is part of the shell it works for all commands, not just grep - I can't remember the last time I needed to use find ... | xargs ...


4. Andy Lester left...
2008.12.23 Tue 6:55 am :: http://petdance.com/ack/

There are plenty of examples on the ack home page at http://petdance.com/ack/.

grep -R . does not let you select or omit certain filetypes. Indeed, grep -R . doesn't search only for source.

grep -R . does not use real Perl regular expressions, allowing you to use $1, $2, etc in the output.

grep -R . does not skip over .git, .svn and other directories you want to skip

grep -R . is triple the keystrokes of ack.

grep -R . is not also a file-finding utility.

ack's install is trivial:

curl http://ack.googlecode.com/svn/tags/latest/ack-standalone > ~/bin/ack && chmod 0755 !$