<tt>grep</tt>: Global Regular Expression Printer



next up previous contents
Next: sed: Stream Editor Up: Utilities Previous: dd: Image Copy

grep: Global Regular Expression Printer

grep finds a string in a specified list of file(s).

grep [-in] expression [filename...]
where expression is a literal which may contain metacharacters (in which case, the literal must be in quotes), and filename... may be one or more files.

Some useful options are:

-i
: ignore case, i.e. treat upper and lower case the same.
-n
(numbers): print the line number of the expression in the file.

For example, to find, in every file ending with .dat, every occurrence of Silicon Graphics, use

grep -i "Silicon Graphics" *.dat

Or, to find the string Claude Cantin in files personnel and payroll.list, use

grep "Claude Cantin" personnel payroll.list

Finally, to find all occurences of prog2 to prog9 in all the files of the directory, use

grep "prog[2-9]" *



Super-User
Fri Feb 17 15:55:40 EST 1995