CIT052 Index > awk Exercise 2

awk Exercise 2

  1. Do lab 4 on page 202 of the book. You will put each answer into a file as a separate awk command. Name the file lastname_firstname_logic.txt. (Download lab4.data.) If you are on the server, copy the file to your home directory with this command:

    cp ~linux199/cit052/lab4.data ~

    Note that, in this part of the assignment, these are all separate questions, not a single script.

    Note: Please change the questions to read as follows:

    3. Print the names of those who contributed between $75 and $200 in the first month.

    5. Print the names and phone numbers of those with an average monthly contribution greater than $200.

    9. Add $10 to Chet’s second contribution and print the changed record.

    10. Change Nancy McNeil’s name to Louise McInnes and print the changed record.

  2. Do lab 5 on pages 226-227 of the book. Please name the file in the form lastname_firstname_contributions.awk. (Download lab5.data.)

    If you are on the server, this command will copy the file to your home directory:

    cp ~linux199/cit052/lab5.data ~

    Your file must not be tied to this specific data. If the amounts change, or if new lines are added to the file, your script must still produce the correct results for that data. Hint: To find the minimum and maximum value, you have to give them an initial value. Since you can't predict the maximum or minimum in advance, you must add code to set the maximum and minimum to the first contribution if this is the first record.

    Hint: to find the minimum of fields 3, 4, and 5, you could use code like the following; see also page 200, section 6.12.7 (the conditional operator).

    {
      min = $3
      min = ($4 < min) ? $4 : min 
      min = ($5 < min) ? $5 : min 
      print "Minimum is ", min 
    }

When You Finish

Zip the files into a file named in the form: lastname_firstname_awk2.zip and upload that file to Moodle. (Or you can make a .tgz file if you prefer.)