$25
Before the lab you should re-read the relevant lecture slides and their accompanying examples.
Create a new directory for this lab called lab08, change to this directory, and fetch the provided code for this week by running these commands:
$ mkdir lab08
$ cd lab08
$ 2041 fetch lab08
Or, if you're not working on CSE, you can download the provided code as a zip file or a tar file.
Write a Shell script courses.sh which given a course prefix, e.g. COMP, prints all the course code and name for all UNSW shell_courses with that prefix offered this year on the Kensington Campus. For example:
$ ./courses.sh VISN
VISN1101 Seeing the World: Perspectives from Vision Science VISN1111 Geometrical and Physical Optics
VISN1221 Visual Optics
VISN2111 Ocular Anatomy and Physiology
VISN2211 Organisation and Function of the Visual System
VISN3111 Development and Aging of the Visual System
VISN4016 Vision Science Honours
./courses.sh COMP|tail
COMP9511 Human Computer Interaction
COMP9517 Computer Vision
COMP9596 Research Project
COMP9801 Extended Design and Analysis of Algorithms COMP9814 Extended Artificial Intelligence
COMP9844 Extended Neural Networks and Deep Learning
COMP9900 Information Technology Project
COMP9991 Research Project A
COMP9992 Research Project B
COMP9993 Research Project C
Your program must be POSIX compatible Shell. You can assume anything that works with the version of /bin/dash on CSE systems is POSIX compatible.
You are not permitted to use other languages such as Perl, Python, C, ...
You are permitted to use programs such as egrep, sed, sort, uniq.
Hints:
The information you need for course code prefix COMP can be found in this web page:
http://www.timetable.unsw.edu.au/current/COMPKENS.html. You can assume this is the case for all prefixes.
The command curl will download a URL and print it to standard output.
$ curl --location --silent http://www.timetable.unsw.edu.au/current/COMPKENS.html|head
<title>Class Search by Teaching Period</title>
<link rel="stylesheet" type="text/css" href="../layout/2020/myunsw.css"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<table width="100%" cellspacing="0" cellpadding="0">
<form name="googleForm" method="GET" action="http://www.google.com/u/theuniversityofnewsouthwales" target="_blank">
<tr>
<td width="30%" style="height:120px; border-bottom:10px solid #FFCC00; background-color:#fff;"><a href="http://www.unsw.edu.au" target="_blank"><img border="0" src="/images-timetable/banner2020.jpg" alt="The
University of New South Wales" width="836" height="179" style="float:left; margin-left:20px; margin-top:25px;">
</a></td>
<td width="70%" style="height:120px; border-bottom:10px solid #FFCC00; background-color:#fff; vertical-align:bottom; " align="right">
$
In a script it is best run as curl --silent so it doesn't print extra information on standard error.
The --location is required so curl will follow a HTTP redirect from the URL.
The wget -q -O- could also be used.
You may find uniq's -w option useful when removing duplicate courses.
Write a Perl script courses.pl which given a course prefix, e.g. COMP, prints all the course code and name for all UNSW courses with that prefix offered this year on the Kensington Campus. For example:
./courses.pl VISN
VISN1101 Seeing the World: Perspectives from Vision Science VISN1111 Geometrical and Physical Optics
VISN1221 Visual Optics
VISN2111 Ocular Anatomy and Physiology
VISN2211 Organisation and Function of the Visual System
VISN3111 Development and Aging of the Visual System
VISN4016 Vision Science Honours
./courses.pl COMP|tail
COMP9511 Human Computer Interaction
COMP9517 Computer Vision
COMP9596 Research Project
COMP9801 Extended Design and Analysis of Algorithms COMP9814 Extended Artificial Intelligence
COMP9844 Extended Neural Networks and Deep Learning
COMP9900 Information Technology Project
COMP9991 Research Project A
COMP9992 Research Project B
COMP9993 Research Project C
Your answer must be Perl only.
You may not run external programs, e.g. via system or backquotes.
Hints:
The information you need for course code prefix COMP can be found in this web page: http://www.timetable.unsw.edu.au/current/COMPKENS.html. You can assume this is the case for all prefixes.
The Perl module LWP::Simple provides a very simple way to get a web page, e.g:
You will need to remove duplicate entries for some courses.
Write a Perl script timetable.pl which given course codes prints an ASCII timetable of their lecture times for this year in the format shown in the example below.
$ ./timetable.pl COMP2041 MATH2400 MATH2859
Mon Tue Wed Thu Fri
09:00 L L
10:00 L L
11:00 L L L
12:00 L 13:00
14:00 L
15:00 L
16:00
17:00
18:00
19:00
20:00
10:00 L
11:00 L
12:00
13:00 L
14:00 L L
15:00 L
16:00 L
17:00 L
18:00 L
19:00 L
20:00
You can assume that a course's lecture times will be found in a web page equivalent to: http://timetable.unsw.edu.au/current/MATH1131.html.
Hint: if you find it difficult to use a regex to extract the line containing the lecture description, split the page into line match a previous line, then skip a certain number of lines.
You may not run external programs, e.g. via system or backquotes.
If a course is running in multiple terms print all the terms.
If th lti l t i t ll th t f l
If there are multiple streams print all the streams, for example:
$ ./timetable.pl COMP1511
Mon Tue Wed Thu Fri
09:00 L
10:00 L
11:00 L
12:00 L
13:00
14:00
15:00
16:00 L
17:00 L
18:00
19:00
20:00
$ ./timetable.pl MATH1131
Mon Tue Wed Thu Fri
09:00 L
10:00 L
11:00
12:00 L
13:00 L L L
14:00 L L L L
15:00 L L L L
16:00 L L L 17:00 L
18:00
19:00
20:00
Note the correct output in all the above examples will change when next term's lectures are added to the timetable.
When you think your program is working, you can use autotest to run some simple automated tests: