Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

petdance (2468)

AOL IM: petdance (Add Buddy, Send Message)
Yahoo! ID: petdance (Add User, Send Message)

I'm Andy Lester, and I like to test stuff. I also write for the Perl Journal, and do tech edits on books. Sometimes I write code, too.

Journal of petdance (2468)

Sunday November 04, 2007
10:50 PM

ack 1.70 adds context and line-specific matching

[ #34832 ]

ack, my replacement for grep for 95% of the times programmers use grep, just got released to CPAN with version 1.70.

At long last, you can now get contextual lines before and after matched lines, just like GNU grep's -A, -B and -C options. You can also match on a specific line number or range of line numbers with the new --line option. For example, if you want to see the first line of every Perl file in a tree, you'd just do ack --line=1 --perl. Thanks very much to Torsten Biix for putting both these features together for me.

Finally, Elliot Shank pointed out that one of my favorite features, the -1 option, was never documented. Now it is. The -1 option says "stop after the first match of any type." If you find yourself acking for lines, or searching for a specific file with ack -g and then having to Ctrl-C to stop the search process, just add a -1 and Ctrl-C no longer.

ack is available in the ack distribution on CPAN, or by installing the module App::Ack from the CPAN shell. You can also download the single-file version direct from Subversion and drop it right into your ~/bin directory.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • But, but, but... []
    is still not resolved *sob*

    When using ack from within Emacs on Windows (yah, a bit of a corner case there), the tty vs pipe makes ack confused.

    And I was so close to emailing you last night asking when you were planning the next release :)
  • Thank you for ack. Thank you doubly for ack-standalone!
    • You're very welcome. Do you just toss the ack-standalone in your ~/bin dir and carry it around? Or is there another reason it's a ++ ?


      • This is the first I had heard of the standalone version. Previously I only had ack installed on my personal system because I am reluctant to do system level installs on any of our servers and I've never had any luck with user-directory cpan installs.

        So, I just copied ack-standalone into ~/bin on one of the servers and it worked great.
        • That's why I have it like that. I think I'm going rename it to ack-single-script or maybe ack-no-dependencies so people notice it more. If you don't have your ~/bin directory in Subversion, do so. Makes it even easier to have everything synced between your machines. The way I do it is documented at [].


          • Yeah, I was just thinking of giving that a try. Perhaps I can even keep ack automatically up to date using svn:externals and a symlink?
          • If others are anything like me, then the problem isn’t that people don’t figure out what “standalone” means, it’s that they install ack from CPAN and never bother to look at its website (let alone the Google Code project). But there is no mention of ack-standalone whatsoever in the distro docs (ie. the parts that exposes prominently), save for a passing one in the Changes. Not even the installation instructions in the README say anything about it. I knew it exis