Tutorial #12 - Using Grep


1. Log on to UNIX if needed.

2. List all the lines in forsorting that contain the character M.

3. List and number all lines in forsorting that contain the 

character s or S.

4. List any lines in new_file that contain neither of the characters 

e or a.

5. List any lines in forexercise that include and . Then list to a file 

the ones that don't include it.

6.Check how many lines in keep.home include the character a  at 

least once.


If it doesn't work:

A. Try these commands for items 2 through 6 if you have trouble:

grep 'M' forsorting
grep -n '[sS]' forsorting
grep -v '[ae]' new_directory
grep 'and' forexercise; grep -v 'and' forexercise > filenotfound
grep -c a keep.home 

B.Try fgrep (or grep -F) for simple strings or 
egrep (or grep -E) for others if you have trouble.

Questions? Robert Katz:rkatz@ned.highline.edu
Last Update July 23, 2002