What's new in ack?
New boolean options --and, --or and --not
The new repeatable --and, --or and --not options lets you get more precise matches. If you want any of "dogs" or "cats" or "fish", use
ack dogs --or cats --or fish
If you want all three on the line:
ack dogs --and cats --and fish
And of course if you want "dogs", but not if "cats" or "fish" are on the line:
ack dogs --not cats --not fish
Easier to understand error messages
The error message ack displays when the regex passed is invalid has been improved. The message is more readable and includes a pointer to the offending part of the regex. For example:
$ ack 'status: (open|closed|in progress' ack: Invalid regex 'status: (open|closed|in progress' Regex: status: (open|closed|in progress ^---HERE Unmatched ( in regex
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 -w option
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 use ack -w foo:, the new ack will not allow it, whereas ack 2.x would.
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, 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.
People love ack
"Every once in a while something comes along that improves an idea so much, you can't ignore it. Such a thing is Ack, the grep replacement."
Follow us on Twitter
We're all about knowing when to move beyond the stock Unix tools. Follow us on Twitter at @beyondgrep for tips, hints and software news.