Search

Thursday, June 18, 2009

GREP: A text-search utility

GREP (Global Regular Expression Print) is a powerful
text-search program derived from the UNIX utility of
the same name. GREP searches for a text pattern in one
or more files or in its standard input stream.
Here's a quick example of a situation where you might
want to use GREP. Suppose you wanted to find out which
text files in your current directory contained the
string "Bob". You would issue the command
grep Bob *.txt
and GREP would respond with a list of the lines in each
file (if any) that contained the string "Bob". Because
the default for GREP is to ignore case, the strings
"bob" and "BoB" would also be considered matches. You
can use options to make your search case sensitive.
GREP can do a lot more than match a single, fixed
string. In the section that follows, you'll see how to
make GREP search for any string that matches a
particular pattern.

No comments:

Post a Comment