If you are a Windows© user you have no doubt used it's built in search function. If you are like me, you've also set it to look for certain words inside files. Well, BASH shell users have had this all along, dating back to the dark ages in computer history (like the early 70s with teh first incarnations of Unix)
The GREP command may have an odd name, but it's a powerful ally when it comes to finding stuff inside files. Let's say you have 4 dozen html files, and one of them has a typo in it. In your haste you misspelled "Home" "Hoem"

and now the real quandry, you aren't sure which file the error is actually in..
Well get to your trusty BASH command prompt and CD to your www directory, and search all the HTML files for the typo
| Code: |
cd www
grep hoem ./*.html
|
If the typo is found it will show you the filename(s) it was found in.
Lets say you want to see 2 preceding lines above the typo, use the -b flag like this
| Code: |
grep -b2 hoem ./*.html
|
That's b as in Before. Simple right

Maybe you also want to see the 2 lines after the typo.. You guessed it! The -a flag
| Code: |
grep -b2 -a2 hoem ./*.html
|
Of course you can search for anything, in any type of file, but the power doesn't stop there. Nope, note even close. Because almost any bash command can have it's output piped to another command, even the same command again...
Lets do the same search as above, but this time pipe the output to a 2nd grep command wich uses the inverse search operation. The inverse search operation matches lines that DO NOT contain the term. So you want to find the typoed word hoem, but ignore matches that also have the word "typo" in them..
| Code: |
grep -b2 -a2 hoem ./*.html |grep -v typo
|
Now you would think that uses the -1 flag

but, it uses -v for inVerse
This is literally just the tip of the iceberg and doesn't even mention using regular expression, which really unleash GREP's power, but hey, you just want to find your way hoem right?
