Académique Documents
Professionnel Documents
Culture Documents
The grep utilities are a family of Unix tools, including grep, egrep, and fgrep,
that perform repetitive searching tasks. The tools in the grep family are very
similar, and all are used for searching the contents of files for information that
matches particular criteria. For most purposes, you'll want to use fgrep, since
it's generally the fastest.
This command would search files with names such as myfile, my.hw1, and
mystuff in the current directory. Each line returned will be prefaced with the
name of the file where the match was found.
By using pipes and/or redirection, you can use the output from any of these
commands with other Unix tools, such as more, sort, and cut. For example, to
print the fifth word of every line of myfile containing "dog", sort the words
alphabetically, and then filter the output through the more command for easy
reading, you would enter at the Unix prompt: fgrep dog myfile | cut
-f5 -d" " | sort | more
If you want to save the output in a file in the current directory named newfile,
enter: fgrep dog myfile | cut -f5 -d" " | sort > newfile
For more information about grep, egrep, and fgrep, enter: man grep
Comments