Unix Systems Programming: Lab 1
Lab time: No assigned lab time due to lab space
construction.
Work at your own pace, but work.
Due: Tuesday, October 6, 2009 @ 5:00 pm
PURPOSE AND RATIONALE
The purpose of this lab is to allow students to become comfortable with
basic Awk programming.
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
- 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
- Please start this lab as earlier as possible
- Before starting, please review lecture 2 notes and read Effective
awk Programming, 3rd ed., by Arnold Robbins, available online
- Turn the lab assignment in by email to the grader by the
due date
above.
- Make sure you have read the Homework Style Guidelines for
submission.
LAB 1
- Create a HERE document which will edit multiple files in
the same
directory,
using the ed editor. I give you 3 original files: file1.c
, file2.c
, file3.c
, download them and change each string "stdio.h" to "STDIO.H" in these
files. Note: when executing your script, it should change all three C
files. You do
not need excute it several times. Only Submit the shell script file and
resulting C
files. Hint: Read Chapter 2, text BLP.
- 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:
- 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.
- 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.
- Use "gawk" to integrate the patterns and actions we
described
above.
DELIVERABLES
Please see the FAQ.
MARKS DISTRIBUTION
- Excercise 1:
- 15 points: shell script
- 10 points: correct execution of the script on files (i.e.
the contents of the files should be changed accordingly)
- Excercise 2:
- 15 points: gawk script
- 8 points: correct answer as generated by the gawk script
- 2 points: correct answer in the submitted file
- Correct Submission:
- 5 points: Lab submitted as given in the
instructions with names on top of files and proper format.
Total Marks: 55
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.
Atilla
Soner Balkir