COS 126 Lecture 14: Pattern Matching

grep

Most common use is for finding a particular word or short string in a file. The syntax is:
grep expression filename(s)

For example, you might want to find all the lines of code in your C files which refer to a particular variable.

grep 'count' *.c

How can you learn about grep?

1. type (on a Unix machine):
man grep

You can copy the manual page for grep to a file using '>' and then print that file. You should learn (or put on your cheat sheet) some of the main options for grep.

2. one of the other TAs has provided some links to documentation with many examples on a FAQ list

3. TRY IT!!

Here's some hints and highlights about grep:


awk

Sorry, no notes yet. Just try it out for yourself, or read about it in a UNIX reference guide.