next up previous
Next: RE in vi: Up: Programs Using Regular Expressions Previous: Programs Using Regular Expressions

Grep and Egrep

Grep and egrep are tools that search for patterns in files and find all lines containing a particular string.
Format:
grep RE filename
(see UNIX in a nutschell and man grep for more detailed description)
Examples:
grep "youruserid" marks - prints all lines which contain 'youruserid' in the file 'marks'
grep "$\backslash$$*$" classlist - prints all lines which contain a character '$*$'.
grep "[Pp]roced.*" *.java - prints all lines which contain Proced or proced in all files with extension java.

Note the significant difference between '$*$' as used in RE and '$*$' used in shell. Since shell may be easily confused by '$*$' or any other special character in regular expression, it is always recommended to quote (by using '' or "") RE.



Instructional Support Group 2008-08-05