ack 1.70 adds context and line-specific matching

petdance on 2007-11-05T03:50:08

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.


*sob*

jplindstrom on 2007-11-05T14:08:16

But, but, but...
http://rt.cpan.org/Public/Bug/Display.html?id=24670
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 :)

Thanks!

stu42j on 2007-11-05T15:54:29

Thank you for ack. Thank you doubly for ack-standalone!

Re:Thanks!

petdance on 2007-11-05T15:57:00

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 ++ ?

Re:Thanks!

stu42j on 2007-11-05T16:28:12

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.

Re:Thanks!

petdance on 2007-11-05T16:37:45

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 http://xoa.petdance.com/How_to:_Keep_your_home_directory_in_Subversion.

Re:Thanks!

stu42j on 2007-11-05T16:57:11

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?

Re:Thanks!

Aristotle on 2007-11-05T18:50:03

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 search.cpan.org 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 exists only because I saw a post of yours mentioning it somewhere on some mailing list.

If you want people to notice it, advertise it in the README and the POD.