Grep
Usage
grep searches the name file or files for the specified string. (You can also use egrep to search inside a file using Regular Expressions )
Case Sensitive
grep bananas filename.txt
This searches for the word bananas in the file, filename.txt
Note that the search is case sensitive. It will not find Bananas, or BANANAS.
If you want it to find all of those, use:
grep -i bananas filename.txt
String-Search
grep searches for strings, not words. It will match partial words, whole words, and that string inside a whole block of text.
So, if I'm looking inside a file for the word "the", and I use:
grep the filename.txt
grep will output all of the following:
- the - themselves - theory - another (etc...)
... wait, we only wanted "the"...
Fortunately, we can tell grep to do that, like so:
grep -w the filename.txt
This will tell grep to only match the word "the".