UNIX ack
ACK [1] is a 99% replacement for the grep and find combination. But not all commands are as obvious unfortunately.
Is ACK better than find and grep?
Yes and No. The trick of ack is it only search for the files it have to look for. If that's not the case find and grep are much faster.
Please remember ACK is written in Perl, find and grep are written in C.
Why this ACK-Page
Since I find the man-pages of ACK not very descriptive I created this Webpage.
This page does not replace the man-page, but is a useful addition.
Please give your comment by sending me an email.
Find-Files
The general syntax for defining a file is: [2]
ack -f --type=<TheType> --type-set <TheType>=<extensions>,[extension]
So, to find Javascript files in all (sub)-directories. The -f command is used to show the result and should be ignored when finding text inside the selection [2].
ack -f --type=script --type-set script=.js
Another example: Find all Excel files with the old (.xls ) and new (.xlsx ) extension [2].
ack -f --type=excel --type-set excel=.xls,.xlsx
Grep-text
If you have specified the correct files (See Find-Files above), you can search for the correct content.
- Don't use the -f option.
- Add the search-text (Hypotheek)
ack --type=excel --type-set excel=.xls,.xlsx Hypotheek
Predefined types
ack --php wfHook
Searches through all the php-files for the occurence of the text 'wfHook'.
Text files
ack UserName --type=text WikiTrace*.txt
Searches the txt files WikiTrace.txt for the occurence of Username.
Codeses
Use -f for working with big codesets
Ack does more than search files. ack -f --perl will create a list of all the Perl files in a tree, ideal for sending into xargs. For example:
# Change all "this" to "that" in all Perl files in a tree. ack -f --perl | xargs perl -p -i -e's/this/that/g'
See also
- UNIX Command Reference Strings, search a binary (dump) for printable Strings.
Reference
- ↑ BetterThanGrep, ACK home page. ack is a tool like grep, optimized for programmers.
- ↑ 2.0 2.1 2.2 Please note: The -f option is only used to show you the result-set. In Search commands this options should not be used