In this lab, you will practice using bash’s process substitution to solve a problem that sh can’t.
The Metro Roasters Cafe wants to send thank-you emails to top customers of the month. Write a bash script to find the email addresses for them.
They provide you with a customer file and a monthly purchase summary file.
Generally the files have one record per line, fields are separated by commas, and there is no extra whitespace.
The customer file has membership card numbers and email addresses, in arbitrary order, but card numbers are unique. Example (sample-customers.csv):
201,robert@gmail.com
1127,alice@mail.utoronto.ca
1078,chandra@bell.ca
1024,moana@disney.com
1337,leet@leet.me
The purchase summary has membership card numbers and amounts, in arbitrary order, but card numbers are unique and are a subset of those in the customer file. (Think of: Each line is one customer’s total purchase over the month, and some customers didn’t make any purchase.) Example (sample-summary.csv):
1127,307.5
201,67.98
1024,102.30
1078,83
Your script needs to output (to stdout) the email addresses (one per line) of the N customers with the highest amounts. We assume that there are no ties. The output order is up to you.
Your script will be run with this syntax:
bash thank-top N CUSTOMERS PURCHASES
Example (sample-output.txt):
$ bash thank-top 2 sample-customers.csv sample-summary.csv
alice@mail.utoronto.ca
moana@disney.com
The script should not (and does not need to) create intermediate files or modify existing files—all you need is pipelining and process substitution. Automarking will be done in a docker container under heavy lockdown.
You will need to find ways to tell them that the field separator is comma, which field to join on, which field to sort on, and some field must be sorted as numbers not strings.
If you like to print debugging or error messages for your own sake, please send them to stderr only.