Ack is better than grep! – And it’s not only their slogan.
I recently was pointed to ack for scanning a huge pile of files for a certain pattern. So far I was always using grep, awk, cut, sed and such in combination with find to build whatever I needed. But having a look at ack reveals that my life could have been much easier. Here are some simple examples:
Search for a pattern recursively through directories, while ignoring .svn, CVS and other VCS directories:
With grep: grep pattern $(find . -type f | grep -v '\.svn')
With ack: ack pattern
Search for a pattern in all perl files, while ignoring .svn directories:
With grep: grep pattern $(find . -name '*.pl' -or -name '*.pm' -or -name '*.pod' | grep -v .svn)
With ack: ack --perl pattern
That’s it for the basics. More on their manual page at http://betterthangrep.com/
Just a last one:
Get a list of all functions and their parameters attached to your “wp_head” action hook of a WordPress installation.
With grep: please don’t make me do it.
With ack: ack "add_action\((.*[\"|'](.*)[\"|'][,|\s]+.*)\)" --output="hook: \$1, params: \$2"
sourcebench 2:14 am on December 21, 2009 Permalink |
Ack is better than grep! – And it’s not only their slogan. – http://bit.ly/6e183w
This comment was originally posted on Twitter