CSCB09 2024 Summer Assignment 1

Due: June 10 11:59PM
This assignment is worth 10% of the course grade.

In this assignment, you will write a shell script that leverages standard Unix utilities to perform a simple but useful task that’s right up the alley of Unix shell scripting.

As usual, you should aim for reasonably efficient algorithms and reasonably well-organized, well-factored, comprehensible code.

Code correctness (mostly auto-marking) is worth 90% of the marks; code quality is worth 10%.

Congratulations Top Students!

UTSC CMS wants to select top students and email them congratulation messages! You will write a shell script to help them.

The input and output formats are:

Part A

Write a shell script high-A in basic sh that can be used as

sh high-A [OPTIONS] ROSTER MARKS

where ROSTER and MARKS are the filenames of a roster file and a mark file, respectively. There is no argument for the output filename—output to stdout.

The options are:

Output the congratulation list of NUM highest-mark students. If there are not enough students, output everyone who has a mark.

Auto-marking will stick to valid syntax and inputs. If you still like to be robust and handle invalid syntax, you may send error messages to stderr and/or exit with a non-zero exit code.

You will need the help of these programs: sort, join, head. You may not write your own loop to process student records. You may not use a program that fundamentally defines a whole different programming language (e.g., perl, awk).

You will need to combine them by pipelining. You may not write “intermediate temporary” files or modify input files. Auto-marking will be under heavy lockdown in a docker container.

Examples:

sh high-A -m -n 2 sample-roster.txt sample-markus.txt
sh high-A -r -n 2 sample-roster.txt sample-ro.txt

Both should produce output identical to sample-stdout.txt.

Part B

Write a shell script high-B in bash that can be used as

bash high-B [OPTIONS] ROSTER

where options and ROSTER are as in part A. But this time, the marks come from stdin, and not initially sorted.

Output (to stdout) the congratulation list of NUM highest-mark students. If there are not enough students, output everyone who has a mark.

Auto-marking will stick to valid syntax and inputs. If you still like to be robust and handle invalid syntax, you may send error messages to stderr and/or exit with a non-zero exit code.

This time you need the help of bash process substitution (e.g., “foo <(bar)”), in addition to pipelining. You may not write your own loop to process student records. You may not use a program that fundamentally defines a whole different programming language (e.g., perl, awk).

You may not write “intermediate temporary” files or modify input files. Auto-marking will be under heavy lockdown in a docker container.

Examples:

bash high-B -m -n 2 sample-roster.txt < sample-markus.txt
bash high-B -r -n 2 sample-roster.txt < sample-ro.txt

Both should produce output identical to sample-stdout.txt.

You should also test with your own mark files that are unsorted or in random order.