Unix Systems Programming: Lab 2

Lab time:   No assigned lab time due to lab space construction.  Work at your own pace, but work.
Due:          Wednesday, October 13, 2010 @ 5:00 pm

PURPOSE AND RATIONALE

The purpose of this lab is to allow students to become comfortable with basic Awk programming, and building static and shared libraries.

PRIMARY RESOURCES:

FAQ (submission instructions and other useful resources)
You should refer to the online Awk text under required texts.
If possible, you should ssh into the cluster to perform all lab activities.

README

  1. If you are not in our course email list, please subscribe to the cspp51081 email list here:  http://mailman.cs.uchicago.edu/mailman/listinfo/cspp51081
  2. Please start this lab as earlier as possible
  3. Before starting, please review lecture 2 notes and read Effective awk Programming, 3rd ed., by Arnold Robbins, available online
  4. Turn the lab assignment in by email to the grader by the due date above.
  5. Make sure you have read the Homework Style Guidelines for submission.

LAB 2

  1. Consider the file normal.precip.txt. It contains the average amount of rainfall over a 30 year period for about 275 cities in North America. The first line of the file is a header, which tells you what each column contains. Basically, each line contains a city name, the state the city is in, and then average rainfall amounts from January through December, and then an annual average for all months. The file is TAB delimited. QUESTION: What is the total average amount of rainfall, in inches, for the month of January, for the following states: California (CA), Texas (TX), Alaska (AK). I want individual totalized averages for each of the above states for the month of January. As a check on your algorithm, note that the totalized average rainfall for California (CA) for the month of February over the same period was 2.65067. This was derived by adding the rainfall values together for all cities in California for the month of February, and simply taking their average.

    Please use Awk programming to implement above procedure. There are several steps for this lab:

    1. Figure out the regular expression that will match all the valid chunks of the form described above. Mark has provided a very useful program to help with this process called showmatch that can be used in the following manner:
      hangao@gawaine:CSPP51081% echo "FOO8AB10BAR" | /home/mark/pub/51081/showmatch '[0-9]AB[0-9]'
      FOO8AB10BAR
      ^^^^
      hangao@gawaine:CSPP51081%
      The matched portion of the string is returned with carrot characters underneath. This will help you understand how "gawk" works.
    2. If a question is about California, notice that a mere grep of /CA/ will include:
      WINNEMUCCA, NV
      POCATELLO, ID
      Probably NOT what you wanted. The shell script "showmatch" maybe help you debug in this regard.
    3. Use "gawk" to integrate the patterns and actions we described above.

    2.   Build Static and Shared Libraries using a Makefile

DELIVERABLES: see the submission faq

MARKS DISTRIBUTION

  1. Excercise 1:
  2. Excercise 2:
  3. Correct Submission:


  4. Total Marks: 25

HINTS

Take it slowly and complete each portion of the homework before working on the next as each step depends upon the correct solution to the last. If you think you have the right answer for a step but the test is still failing, mail the list. If you are having any questions at all, mail the list.


Brian Martin