If you can't see /lab/week9 in your Docker image, you need to update to a newer image by
running the following command outside of your Docker container:
docker pull nebuzaradan/cits4407:v0
Questions
/lab/week9/american_dates.txt contains a list of birthdays in mm/dd/yyyy format.
Use awk to print the file with dates in dd/mm/yyyy format
Use awk to print the file with dates in yyyy/mm/dd format. This one is harder!
What is the difference between $0 and $1 in an awk script? Try printing both and see what you get for
different files
/lab/week9/add_this.txt contains a list of numbers
Use awk to print the cumulative sum of the values on each line. It should look like this:
1
3
6
10
15
21
...
Use awk to print the sum of all values in the file. This should only print the sum at the end of the file.
Your friend has tried to fix up the university enrolment data file from last week, but they've made a mess. Write an
awk script which prints all invalid lines in /lab/week9/australian-universities.csv. Valid lines
must contain 4 fields and the word "University" (corractly capitalised) in the first field.
/lab/week9/original_151.csv is a list of popular portable cartoon creatures. The creatures are listed in numerical order, but
the first column, which lists the number for each creature, has gone missing. Use awk to recreate this column and put the output in a file called
numbered_151.csv. It should look like this:
Note: try and do this using > within awk instead of a shell output redirect.
/lab/week9/height_weight_151.csv lists creature names followed by their height in m and weight in kg. Use printf in awk to print the
heights and weights in the following format:
Bulbasaur is 0.7m tall and weighs 6.9kg
Ivysaur is 1.0m tall and weighs 13.0kg
Venusaur is 2.0m tall and weighs 100.0kg
Charmander is 0.6m tall and weighs 8.5kg
Charmeleon is 1.1m tall and weighs 19.0kg
...
Use awk to print the name of the tallest creature in height_weight_151.csv
Use awk to print the name of the tallest creature in both height_weight_151.csv and
more_height_weight.csv
Create a pipeline using paste and awk to join original_151.csv
and height_weight_151.csv and then print creature information in the following format:
Note: For this question, you may ignore the second type for each creature. As a bonus exercise, modify your answer to
print both types for creatures that have two.
Hint: it will help if you use comma as the paste field delimiter.
Use awk to print a count of creatures of each type.
Remember that each creature in original_151.csv has two type fields. You may find it easier to write an awk script
instead of trying to cram it all on one line. You can call an awk script with awk -F"," -f types.awk original_151.csv
Modify your previous answer to print a list of creatures for each type instead of a count
Bonus
Use awk to calculate the average creature height and weight
Write an awk command to fix the incorrect capitalisation of university names using toupper and tolower
Department of Computer Science & Software Engineering
The University of Western Australia
Last modified: 8 February 2022
Modified By: Daniel Smith