ack is the replacement I wrote for grep, aimed at large trees of heterogeneous code.
Using it will change your life, but why? Here's my top 10 list:
- Searches recursively through directories by default, while ignoring
.svn, CVS and other VCS directories.
- Which would you rather type?
$ grep pattern $(find . | grep -v .svn)
$ ack pattern
- Which would you rather type?
- ack ignores most of the crap you don't want to search
- VCS directories
- blib, the Perl build directory
- backup files like foo~
- binary files
- Lets you specify file types to search, as in --perl or --nohtml.
- Which would you rather type?
$ grep pattern $(find . -name '*.pl' -or -name '*.pm' -or -name '*.pod' | grep -v .svn)
$ ack --perl pattern
- Which would you rather type?
- File-filtering capabilities usable without searching with ack -f. Want a list of all Perl files in a tree? Use ack -f --perl.
- Color highlighting of search results.
- Uses real Perl regular expressions, not a GNU subset.
- Allows you to specify output using Perl's special variables
- Example: ack '(Mr|Mr?s). (Smith|Jones)' --output='$&'
- Many command-line switches are the same as in GNU grep:
-w does word-only searching
-c shows counts per file of matches
-l gives the filename instead of matching lines
etc. - ack is pure Perl, so consistent across all platforms.
- Command name is 25% shorter. :-) Heck, it's 50% shorter compared to grep -r.
To install it, install the Perl module App::Ack. Your coding life will never be the same.
Visit the home page at http://petdance.com/ack
xoxo,
Andy
Back to
Cool Uses for Perl