14.H: Sort with sort | 14: File Utilities | 14.F: Find with find |
The grep command (and its relatives egrep for expression grep and fgrep for fast grep) are great for finding some specific information in a file, or for finding which files contain some specific information. For example, to search all files in the present directory for the word Jack
> egrep Jack *
Here * is a wildcard which gets replaced by all file names. Unix will then show you the names of the files containing the word Jack, and the lines containing the word:
sample.doc:Jack and Jill went up the hill
sample.doc:Jack fell down and broke his crown
So now you know both what is said about Jack, and where it is said.
Like most Unix commands, the greps are case sensitive. For example,
> grep jack *
may well find nothing. If you want grep to be case insensitive, you can use the option -i to make it ignore the case:
> grep -i jack *
Be warned, the grep family may have some
difficulty searching for phrases containing punctuation and special characters.
For example, grep will interpret >
to be an output redirection character and not part of your search string.
On some systems, enclosing your string in single quotes
Check your man pages and the references for the proper syntax for each of the greps and for specialized searches.
14.H: Sort with sort | 14: File Utilities | 14.F: Find with find |