Assignment 1
Due date: Thursday, January 16th at 11:55 pm.
Please note that all of the commands and techniques you need to solve this assignment were given in class. No internet searches should be necessary to complete this assignment. If you aren't sure where to start, review the class slides.
The purpose of this assignment is to practise your bash scripting skills on a data set. Before you begin, be sure to create a new directory to hold your assignment, and move into that directory:
[ejspence.mycomp]
[ejspence.mycomp] pwd
/c/Users/ejspence/EES1137
[ejspence.mycomp]
[ejspence.mycomp] mkdir assignment1
[ejspence.mycomp]
[ejspence.mycomp] cd assignment1
[ejspence.mycomp]
[ejspence.mycomp] pwd
/c/Users/ejspence/EES1137/assignment1
[ejspence.mycomp]
From within this directory, perform the following steps to download the data for this assignment.
[ejspence.mycomp]
[ejspence.mycomp] curl -O https://pages.scinet.utoronto.ca/~ejspence/UTSCfile
[ejspence.mycomp]
[ejspence.mycomp] ls
UTSCfile
[ejspence.mycomp]
[ejspence.mycomp] tar -zxf UTSCfile
[ejspence.mycomp]
[ejspence.mycomp] ls
data UTSCfile
[ejspence.mycomp]
[ejspence.mycomp] cd data
[ejspence.mycomp]
[ejspence.mycomp] pwd
/c/Users/ejspence/EES1137/assignment1/data
[ejspence.mycomp]
The curl
command downloads files from the internet. The -O
flag tells curl to download the file without changing the file name.
The tar
command unbundles a file which contains many other files. The -x
flag tells tar to extract the file, -z
indicates that the file has been gzipped (a type of compression), and the -f
flag is used to indicate the file to apply the operation to.
This data represents the results of interviews of patients which have undergone auditory surgery. The data were collected by different graduate students, with the data from each student in a different directory. Once your data has been uncompressed, spend a little time examining the content of the directories, and the content of the files, so that you will understand what is being requested in the assignment.
1) Write a script called youngest.sh
, which is to be run from the 'data' directory downloaded above. The script takes the name of one of the directories as an argument. The script is to determine and output the date of birth of the youngest entry in that directory. If there are multiple entries with the same youngest value, the first which is found should be output.
The script will be sourced from the command line, and should output similarly to below.
[ejspence.mycomp] pwd
/c/Users/ejspence/EES1137/assignment1/data
[ejspence.mycomp]
[ejspence.mycomp] source youngest.sh Lawrence
Lawrence/Data0483:Year/month of birth: 1999/12
[ejspence.mycomp]
[ejspence.mycomp] pwd
/c/Users/ejspence/EES1137/assignment1/data
[ejspence.mycomp]
[ejspence.mycomp] source youngest.sh Frank_Richard
Frank_Richard/data_540:Year/month of birth: 1999/10
[ejspence.mycomp]
[ejspence.mycomp] source youngest.sh THOMAS
THOMAS/0485:Year/month of birth: 1999/12
[ejspence.mycomp]
2) Write another script called countSats.sh
, also to be run from the 'data' directory, and which also takes a directory name as an argument. This script should count and output the number of files which were reported on a Saturday, for that directory.
[ejspence.mycomp] pwd
/c/Users/ejspence/EES1137/assignment1/data
[ejspence.mycomp]
[ejspence.mycomp] source countSats.sh Lawrence
The number of files in Lawrence reported on a Saturday is 10.
[ejspence.mycomp]
[ejspence.mycomp] pwd
/c/Users/ejspence/EES1137/assignment1/data
[ejspence.mycomp]
[ejspence.mycomp] source countSats.sh Frank_Richard
The number of files in Frank_Richard reported on a Saturday is 8.
[ejspence.mycomp]
[ejspence.mycomp] source countSats.sh THOMAS
The number of files in THOMAS reported on a Saturday is 7.
[ejspence.mycomp]
Some points to consider:
- Full points will be awarded for implementations which store the number of files reported on Saturdays in a local variable, before printing the output.
- Similarly, full points will be awarded for solutions which use do not use
grep -c
. - Do not "hard code" the answers. This means you should not have the numbers 10 or 7, nor the string "Lawrence", anywhere in your script.
- Mac users may find that there is extra white space around the numbers in their output sentences. Do not worry about this white spaces, extra spaces within the sentences are not important.
- After the script is finished running you should be in the same directory you were in before the script was run, the data directory.
- The TAs will test your scripts by running them on their computers. DO NOT put anything into your script which will prevent it from being run on somebody else's computer.
Submit both ".sh" files. Do not submit the data. Assignments will be graded on 10 points basis. Due date is January 16th 2025 (midnight), with 0.5 point penalty per day for late submission until the cut-off date of January 23th, 2025.