Grep: Difference between revisions
No edit summary |
No edit summary |
||
Line 25: | Line 25: | ||
grep will output all of the following: | grep will output all of the following: | ||
- the | - the<br /> | ||
- themselves | - themselves<br /> | ||
- theory | - theory<br /> | ||
- another | - another<br /> | ||
(etc...) | (etc...) | ||
Revision as of 04:28, 22 December 2016
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".