Articles to check out:

* https://www.digitalocean.com/community/tutorials/how-to-install-and-use-ack-a-grep-replacement-for-developers-on-ubuntu-14-04
* http://beyondgrep.com/why-ack/
* http://readwrite.com/2010/11/10/how-to-search-your-source-with

GREP (rinIE) or EGREP (rinI)

the all round search utility

NOTE: the grep article recommend -inIEr, but thats hard to remember, so I prupose rinIE. which is easier because its like a wierd english name for a puppy. rinie. With the last to letters capitalized. Rather then some middle two letters capitalized.

-r makes it look recursively thru folder
-i doesnt care about case
-I skips looking thru binary files (it has a smart algo to find out which files are binary so it can skip them)
-E with regular grep makes it an egrep. If your using egrep you can skip using -E. -E allows you more regex operations for better searching.
ex: If I want to search for the words potato or hamster. I could do this: grep -e "potato" -e "hamster"  or with egrep "potato|hamster"  or with grep -E "potato|hamster" “match folder” is the regular expression or word you want to look for
/folder is where you want to look. If you want to look thru the current directory and its subfolders & files, use “.”

Then if you want to look around use -A# -B# -C#
With -A5 for every match it will show you the results of 5 lines after
With -B5 for every match it will show you the results of 5 lines befores as well
With -C5 for every match it will show you 5 lines before and after

Dont forget -w, which matchs only a word. So for example

Will match “or” “for” “floor”
But if you just want to find the word “or” add the w

 

ACK

the source code search tool made with the powers of perl

An even better tool is ACK which is a program with a soul purpose of looking for source code. So it skips binary files and it has a nicer way of outputting results then grep.

Now to use ack you have to type “ack-grep”, which is too long. So lets dpkg-divert it or symlink it to its proper and actual name “ack”

To use ack, navigate to the root of source code heirarchy

To list all of the files it will search

Grep would of looked thru all of these

Of course grep -I would look thru less as it will not look thru binaries. However ack has an even better sense of what to look thru.

Also you can mess around with -w, -A, -B, -C just like with grep.

Leave a Reply

Your email address will not be published. Required fields are marked *