CSCI 3190 (Directed Study (Unix Power Tools)), Spring 2004:
Homework 8

Assigned:
April 19, 2004.

Due:
April 26, 2004, at 5pm.

Credit:
10 points.

Reading

Read about the following topics, either by skimming the mentioned online references or in another book or reference.

  1. Basics of regular expressions. Covered in the man or info pages for grep and sed. (If you find this presentation hard to understand, try the online tutorial Learning to Use Regular Expressions.)

Problems

Answer the following questions. You may write out your answers by hand or using a word processor or other program, but please submit hard copy, either in class or in my mailbox in the department office. Answers to most questions will involve experimentation on a Unix or Linux system. You are free to use any appropriate system; if you use something other than Red Hat Linux please tell me what.

  1. (2 points) Write a grep command to search all the files in the current directory for lines containing either your first name or your pet's name. (If you don't have a pet, make up a second name.)

  2. (2 points) Write a grep command to search all files in the current directory for strings of the form CSCI-xxxx, where xxxx is four decimal digits.

  3. (2 points) Suppose you have a C program in file foo.c that uses variable x as an all-purpose integer loop counter. Write a sed command that will rename this variable to i everywhere it occurs but will not change other occurrences of the letter x. (Note that essentially the same command would work in vim.)

  4. (4 points) Suppose you have a text file containing a list of names in ``Lastname, Firstname Middlename'' form. Write a sed command to convert this file so that the names appear in the form ``Firstname Middlename Lastname''. (Hint: Backreferences may be useful.)



Berna Massingill
2004-04-19