Jump to content
Nytro

ack - Source code Grep

Recommended Posts

Posted

ack - Source code Grep

ack is a tool like grep, designed for programmers with large trees of heterogeneous source code. ack is written purely in Perl, and takes advantage of the power of Perl's regular expressions.

[h=2]Latest version of ack: 1.96, September 18, 2011[/h] Read the Changelog

[h=2]How to install ack[/h] It can be installed any number of ways:

  • Install the CPAN module App::Ack. If you are a Perl user already, this is the way to go.
  • Download the standalone version of ack that requires no modules beyond what's in core Perl, and putting it in your path. If you don't want to mess with setting up Perl's CPAN shell, this is easiest.

    curl
    http://betterthangrep.com/ack-standalone
    > ~/bin/ack && chmod 0755 !#:3


  • Install the Macport: /trunk/dports/perl/p5-app-ack/Portfile – MacPorts
  • Install the Debian package: ack-grep
    • To install ack-grep as "ack" instead of "ack-grep", use this command:
      sudo dpkg-divert --local --divert /usr/bin/ack --rename --add /usr/bin/ack-grep

    [*]Install the Ubuntu package: ack-grep

    [*]Install the Fedora package: ack

    [*]Install the Gentoo package: sys-apps/ack

    [*]Install the Arch package: community/ack

[h=2]Top 10 reasons to use ack instead of grep.[/h]

  1. It's blazingly fast because it only searches the stuff you want searched.
  2. ack is pure Perl, so it runs on Windows just fine. It has no dependencies other than Perl 5.
  3. The standalone version uses no non-standard modules, so you can put it in your ~/bin without fear.
  4. Searches recursively through directories by default, while ignoring .svn, CVS and other VCS directories.
    • Which would you rather type?
      $ grep pattern $(find . -type f | grep -v '\.svn')
      $ ack pattern

[*]ack ignores most of the crap you don't want to search

  • VCS directories
  • blib, the Perl build directory
  • backup files like foo~ and #foo#
  • binary files, core dumps, etc

[*]Ignoring .svn directories means that ack is faster than grep for searching through trees.

[*]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

Note that ack's --perl also checks the shebang lines of files without suffixes, which the find command will not.

[*]File-filtering capabilities usable without searching with ack -f. This lets you create lists of files of a given type.

$ ack -f --perl > all-perl-files

[*]Nicer and more flexible color highlighting of search results.

[*]Uses real Perl regular expressions, not a GNU subset.

[*]Allows you to specify output using Perl's special variables. To find all #include files in C programs:

  • ack --cc '#include\s+<(.*)>' --output '$1' -h

[*] Many command-line switches are the same as in GNU grep, so you don't have to relearn two sets:

-w does word-only searching

-c shows counts per file of matches

-l gives the filename instead of matching lines

etc.

[*]Command name is 25% fewer characters to type! Save days of free-time! Heck, it's 50% shorter compared to grep -r.

Download:

http://betterthangrep.com/ack-standalone

More info: ack 1.96 -- better than grep, a source code search tool for programmers

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...