|The grep Utility is closely
related to the "egrep" and "fgrep"
utilities that we will not discuss here. The other two versions of
"grep" have other capabilities but you will most likely never need them as a
web technician. Of course, you can always check them out using the
"man" utility as discussed on the first day of this tutorial.
As you might expect, grep accepts several useful options
that are discussed in the table below:
||Prints the matching line with the block number
||Displays the number of matching lines
||A special type of pattern match for when the pattern starts with
a "-" character
||Instructs grep to use the pattern defined in the given file.
||Censors the file name from the display
||Matches case insensitively.
||Displays the list of filenames with matching content only (not the lines)
||Displays the matching line numbers as well as the line
||Censors error messages
||Displays non-matching lines
Let's look at a few common examples of how
to use grep.
Suppose you changed your email address and wanted to
find all the web pages in a given directory that reference the old
address so that you could modify them. In the following example, we
search for firstname.lastname@example.org and find two files we need to modify. Can
you imagine how long it would take to search each file by hand!!!