Before the lab you should re-read the relevant lecture slides and their accompanying examples.
Create a new directory for this lab called lab01, change to this directory, and fetch the provided code for this week by running these commands:$ mkdir lab01$ cd lab01$ 2041 fetch lab01Or, if youre not working on CSE, you can download the provided code as a zip file or a tar file.
There is a template file named dictionary_answers.txt which you must use to enter the answers for this exercise.Download dictionary_answers.txt, or copy it to your CSE account using the following command:$ cp -n /web/cs2041/20T2/activities/dictionary/dictionary_answers.txt .The autotest scripts depend on the format of dictionary_answers.txt so just add your answers dont otherwise change the file. In other words edit dictionary_answers.txt:gedit dictionary_answers.txt &On most Unix systems you will find one or more dictionaries containing many thousands of words typically in the directories/usr/share/dict/.Weve created a dictionary named dictionary.txt for this lab exercise.Download dictionary.txt, or copy it to your CSE account using the following command:$ cp -n /web/cs2041/20T2/activities/dictionary/dictionary.txt .
$ ls -l total 4lrwxrwxrwx 1 cs2041 cs2041 17 May 26 10:36 dictionary.txt -> ../dictionary.txt-rw-rr 1 cs2041 cs2041 1072 May 26 10:36 dictionary_answers.txt. Write an egrep command that prints the words in dictionary.txt which contain in characters lmn consecutively.Hint: it should print:Selmner Selmners almner almners calmness calmnesss calmnessesThe COMP2041 class account contains a script named autotest that automatically runs 1 or more tests on your lab exercises. Once you have entered you answer for q1 you can check it like this:2041 autotest dictionary q1Test q1 (egrep ^Q1 answer dictionary_answers.txt|tail -1|sed s/.*answer[: ]*//|sh) passed 1 tests passed 0 tests failedPassing the autotest doesnt guarantee your answer is correct, of course, but it may find a mistake youve missed so run autotest for each of the following questions when youve entered the answer in dictionary_answers.txt.. Write a shell pipeline that prints the words that contain zz, but do not end in apostrophe-s (s)? Hint: it should print:AbruzziArezziniArezzoBarozziBelshazzarBrazzavilleBuzzBuzzell. Write an egrep command that prints the words that contain four consecutive vowels? Hint: it should print these words:AieaAieasAraguaiaAraguaiasDouaiDouaisGraeaeGraiae. Write an egrep command that prints words which contain all 5 vowels aeiou in that order? The words may contain more than 5 vowels but they must contain aeiou in that order.Hint: it should print these words:abstemious abstemiously abstemiousness abstemiousnesss abstemiousnesses abstentious adenocarcinomatous adventitious. Write an egrep command that prints which contain the vowels aeiou in that order and no other vowels. Hint: it should print these words:abstemious abstemiously abstentious arsenious caesious facetious facetiouslyWhen you think your program is working, you can use autotest to run some simple automated tests:$ 2041 autotest dictionaryAutotest Results96% of 607 students who have autotested dictionary_answers.txt so far, passed all autotest tests.99% passed test q1 q2100% passed test q3 q498% passed test q5When you are finished working on this exercise, you must submit your work by running give:$ give cs2041 lab01_dictionary dictionary_answers.txtbefore Sunday 14 June 17 59 to obtain the marks for this lab exercise.
There is a template file named parliament_answers.txt which you must use to enter the answers for this exercise.Download parliament_answers.txt, or copy it to your CSE account using the following command:$ cp -n /web/cs2041/20T2/activities/parliament/parliament_answers.txt .The autotest scripts depend on the format of parliament_answers.txt so just add your answers dont otherwise change the file.In this exercise you will analyze a file named parliament.txt containing a list of the members of the Australian House of Representatives (MPs).Download parliament.txt, or copy it to your CSE account using the following command:$ cp -n /web/cs2041/20T2/activities/parliament/parliament.txt .
. Write an egrep command that will print all the lines in the file where the electorate begins with W.Hint: it should print these lines:Hon Scott Buchholz: Member for Wright, QueenslandHon Tony Burke: Member for Watson, New South WalesMr Nick Champion: Member for Wakefield, South AustraliaMr Stephen Jones: Member for Whitlam, New South WalesMr Peter Khalil: Member for Wills, VictoriaMr Llew OBrien: Member for Wide Bay, QueenslandDr Kerryn Phelps AM: Member for Wentworth, New South WalesMs Anne Stanley: Member for Werriwa, New South WalesMs Zali Steggall OAM: Member for Warringah, New South Wales Hon Dan Tehan: Member for Wannon, Victoria. Write an egrep command that will list all the lines in the file where the MPs first name is Andrew. Hint: it should print these words:Hon Andrew Gee: Member for Calare, New South WalesMr Andrew Giles: Member for Scullin, VictoriaMr Andrew Hastie: Member for Canning, Western AustraliaMr Andrew Laming: Member for Bowman, QueenslandHon Dr Andrew Leigh: Member for Fenner, Australian Capital TerritoryMr Andrew Wallace: Member for Fisher, Queensland Mr Andrew Wilkie: Member for Denison, Tasmania. Write an egrep command that will print all the lines in the file where the MPs surname (last name) ends in the letters ll. Hint: it should print these words:Mr Julian Hill: Member for Bruce, VictoriaMr Brian Mitchell: Member for Lyons, TasmaniaMr Rob Mitchell: Member for McEwen, VictoriaMs Zali Steggall OAM: Member for Warringah, New South Wales. Write an egrep command that will print all the lines in the file where the MPs name and the electorate ends in the letter y.Hint: it should print these lines:Mr Rowan Ramsey: Member for Grey, South Australia. Write an egrep command that will print all the lines in the file where the MPs name or the electorate ends in the letter y.Hint: it should print these lines:Dr Anne Aly: Member for Cowan, Western AustraliaHon Linda Burney: Member for Barton, New South WalesMr Pat Conroy: Member for Shortland, New South WalesMr Chris Crewther: Member for Dunkley, VictoriaMr Milton Dick: Member for Oxley, QueenslandHon Damian Drum: Member for Murray, VictoriaMs Nicolle Flint: Member for Boothby, South AustraliaHon Ed Husic: Member for Chifley, New South WalesHon Bob Katter: Member for Kennedy, QueenslandMs Ged Kearney: Member for Batman, VictoriaMr Craig Kelly: Member for Hughes, New South WalesHon Dr Mike Kelly AM: Member for Eden-Monaro, New South WalesHon Michelle Landry: Member for Capricornia, QueenslandHon Sussan Ley: Member for Farrer, New South WalesMrs Melissa McIntosh: Member for Lindsay, New South WalesHon Ben Morton: Member for Tangney, Western AustraliaMr Llew OBrien: Member for Wide Bay, QueenslandHon Tanya Plibersek: Member for Sydney, New South WalesMr Rowan Ramsey: Member for Grey, South AustraliaMs Michelle Rowland: Member for Greenway, New South WalesHon Tony Smith: Member for Casey, Victoria. Write an egrep command to print all the lines in the file where there is any word in the MPs name or the electorate name that ends in ng.Hint: it should print these lines:Mr John Alexander OAM: Member for Bennelong, New South WalesHon Josh Frydenberg: Member for Kooyong, VictoriaMr Luke Gosling OAM: Member for Solomon, Northern TerritoryMr Andrew Hastie: Member for Canning, Western AustraliaHon Catherine King: Member for Ballarat, VictoriaMs Madeleine King: Member for Brand, Western AustraliaMr Andrew Laming: Member for Bowman, QueenslandHon Bill Shorten: Member for Maribyrnong, VictoriaMr Terry Young: Member for Longman, Queensland. Write an egrep command that will print all the lines in the file where the MPs surname (last name) both begins and ends with a vowel.Hint: it should print these lines:Hon Anthony Albanese: Member for Grayndler, New South Wales Ms Cathy OToole: Member for Herbert, Queensland. Most electorate have names that are a single word, e.g. Warringah, Lyons & Grayndler. A few electorates have multiple word names, for example, Kingsford Smith. Write an egrep command that will print all the lines in the file where the electorate name contains multiple words (separated by spaces or hyphens). Hint: it should print these lines:Hon Mark Butler: Member for Port Adelaide, South AustraliaHon Barnaby Joyce: Member for New England, New South WalesHon Dr Mike Kelly AM: Member for Eden-Monaro, New South WalesMr Llew OBrien: Member for Wide Bay, QueenslandHon Matt Thistlethwaite: Member for Kingsford Smith, New South WalesHon Jason Wood: Member for La Trobe, VictoriaMr Trent Zimmerman: Member for North Sydney, New South Wales. Write a shell pipeline which prints the 8 Australians states & territory in order of the number of MPs they have. It should print only the number of MPs, followed by the name of the states/territories. It should print them from fewest to most MPs.Hint: check out the Unix filters cut, sort, uniq in the lecture notes.Hint: it should print these lines:1 Australian Capital Territory2 Northern Territory5 Tasmania9 South Australia15 Western Australia27 Queensland33 Victoria45 New South Wales. Challenge: The most common first name for an MP is Andrew. Write a shell pipeline which prints the 2nd most common MP first name. It should print this first name and only this first name.Hint: check out the Unix filters cut, sort, sed, head, tail & uniq in the lecture notes.Hint: it should print this line:TonyWhen you think your program is working, you can use autotest to run some simple automated tests:$ 2041 autotest parliamentAutotest Results83% of 592 students who have autotested parliament_answers.txt so far, passed all autotest tests. 99% passed test q185% passed test q10 100% passed test q299% passed test q3100% passed test q498% passed test q5 99% passed test q698% passed test q7 q897% passed test q9When you are finished working on this exercise, you must submit your work by running give:$ give cs2041 lab01_parliament parliament_answers.txtbefore Sunday 14 June 17 59 to obtain the marks for this lab exercise.
There is a template file named ab_answers.txt which you must use to enter the answers for this exercise.Download ab_answers.txt, or copy it to your CSE account using the following command:$ cp -n /web/cs2041/20T2/activities/ab/ab_answers.txt .Use egrep to test your answers to these questions.Try to solve these questions using the standard regular expression language described in lectures.. Write a egrep command that prints the lines in a file named input.txt containing containing at least one A and at least one B. For example:Matching Not MatchingAndrews favourite Band is not George is BrillantABBA AndrewBA BAB ASo to test with egrep you might do this:cat >input.txt <<eofAndrews favourite Band is notGeorge is BrillantABBAAndrewABBAA B eofegrep REGEXP input.txt Andrews favourite Band is notABBAABBA. Write a egrep command that prints the lines in a file named input.txt containing only the characters A and B such that all pairs of adjacent As occur before any pairs of adjacent Bs. In other words if there is pair of Bs on the line , there can not be a pair of As afterwards.Matching Not MatchingABAABAABAABBBBABB BBAAABBA ABBAAABAAAAAAAAAABBA ABBABABABABAAABABABABA ABBBAAAA BBABABABABABABAA. Write a egrep command that prints the lines in a file named input.txt containing only the characters A and B such that the number of As is divisible by 4.Matching Not MatchingAAAA AAAAABABABABAB ABABBBBBBBBBBBBBBBAAAAAAABBBBAAAA AAAABBABBAAAABBBAABBBBBAABBBAAAA BBBAABBABBBAABBBAAAA. Write a egrep command that prints the lines in a file named input.txt containing only the characters A and B such that there are exactly n As followed by exactly n Bs and no other characters.Matching Not MatchingAAABBB AAABBAB BAAABB AABBBAAAABBBB AAAABBBBAWhen you think your program is working, you can use autotest to run some simple automated tests:$ 2041 autotest abAutotest Results40% of 366 students who have autotested ab_answers.txt so far, passed all autotest tests.95% passed test q181% passed test q276% passed test q346% passed test q4When you are finished working on this exercise, you must submit your work by running give:$ give cs2041 lab01_ab ab_answers.txtbefore Sunday 14 June 17 59 to obtain the marks for this lab exercise.
When you are finished each exercises make sure you submit your work by running give.You can run give multiple times. Only your last submission will be marked.Dont submit any exercises you havent attempted.If you are working at home, you may find it more convenient to upload your work via gives web interface.Remember you have until Sunday 14 June 17 59 59 to submit your work.You cannot obtain marks by e-mailing your code to tutors or lecturers.You check the files you have submitted here.Automarking will be run by the lecturer several days after the submission deadline, using test cases different to those autotest runs for you. (Hint: do your own testing as well as running autotest.)After automarking is run by the lecturer you can view your results here. The resulting mark will also be available via gives web interface.Lab MarksWhen all components of a lab are automarked you should be able to view the the marks via gives web interface or by running this command on a CSE machine:$ 2041 classrun -sturec
Reviews
There are no reviews yet.