ack 3 is a greplike tool optimized for searching large code trees. It’s available at https://beyondgrep.com.

The version 3.0.0 release provides a number of new changes and capabilities.

New features

New --proximate option groups matches near each other

A new option --proximate=N groups together lines of output that are within N lines of each other in the file. This is useful when looking for matches that are related to each other.

For example, these results:

15: First match
18: Second match
19: Third match
37: Fourth match

look like this with --proximate=1.

15: First match

18: Second match
19: Third match

37: Fourth match

Improved and incompatible -w option for word matching

The -w option, which tells ack to only find whole-word matches, did not always work if your pattern began or ended with puncutation. ack would make guesses as to what your intent was, but it was not well-defined. Now, ack disallows regexes that begin or end with non-word characters.

This means that if you try ack -w foo:, the new ack will not allow it because : is not a word character.

Added -S as a synonym for --smart-case

For those without --smart-case always on, the -S will be easier for when you do want to use it.

Smart-case matching makes ack do a case-insensitive search unless the pattern being matched has a capital letter in it.

Added -I to force case-sensitivity

If you use --smart-case in your .ackrc configuration file, you can use -I to force case-sensitivity instead of having to use --no-smart-case (which still works).

Significant speed improvements

Run times for ack 3 compared to ack 2.22 are 30-40% faster because of removal of unused infrastructure for plugins.

New built-in filetypes

ack now supports SVG, Markdown and POD by default.

Bug fixes

  • Column numbers were not getting colorized in the output. Added --color-colno option and ACK_COLOR_COLNO environment variable.

  • A pattern that wanted whitespace at the end could match the linefeed at the end of a line. This is no longer possible.

Incompatibilities with ack 2

ack 3 requires Perl 5.10.1

ack 2 only needed Perl 5.8.8. This shouldn’t be a problem since 5.10.1 has been out since 2009.

-w is fussier

ack 3 will not allow you to use -w with a pattern that doesn’t begin or end with a word character.

ack 3 no longer highlights capture groups.

ack 2 would highlight your capture groups. For example,

ack '(set|get)_foo_(name|id)'

would highlight the set or get, and the name or id, but not the full set_user_id that was matched.

This feature was too confusing and has been removed. Now, the entire matching string is highlighted.

ack 3’s –output allows fewer special variables

In ack 2, you could put any kind of Perl code in the --output option and it would get evaluated at run time, which would let you do tricky stuff like this gem from Mark Fowler (http://www.perladvent.org/2014/2014-12-21.html):

ack --output='$&: @{[ eval "use LWP::Simple; 1" && length LWP::Simple::get($&) ]} bytes' \
                'https?://\S+' list.txt
http://google.com/: 19529 bytes
http://metacpan.org/: 7560 bytes
http://www.perladvent.org/: 5562 bytes

This has been a security problem in the past, and so in ack 3 we no longer eval the contents of --output. You’re now restricted to the following variables: $1 thru $9, $_, $., $&, $`, $' and $+. You can also embed \t, \n and \r , and $f as stand-in for $filename in ack2 --output .

ack 3 no longer uses the ACK_OPTIONS environment variable

The ACK_OPTIONS variable was used to supply command line arguments to ack invocations. This has been removed. Use an ackrc file instead.

ack 3 no longer has the --lines option

The --lines option let you select a specific range of lines to print, and not match. There are other better ways to do this (sed, for example).

Acknowledgements

Thanks to everyone who helped contribute to this new release, including Bill Ricker, Rob Hoelz, Slaven Rezić, Shlomi Fish, Axel Beckert and Mitch Lacy.