COMP(2041_9044) 22T2 — Week 01 Laboratory Sample Solutions

pdf

School

University of New South Wales *

*We aren’t endorsed by this school

Course

2041

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

12

Uploaded by BrigadierDolphin281

Report
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 1/12 lab01 $ mkdir lab01 $ cd lab01 $ 2041 fetch lab01 dictionary_answers.txt dictionary_answers.txt # Open a text editor (gedit) in the background (&) and not owned by the current terminal (disown) $ gedit dictionary_answers.txt & disown # Or use any other text editor of your choosing /usr/share/dict/ $ ls -1 /usr/share/dict/ README.select-wordlist british-english cracklib-small words -> /etc/dictionaries-common/words -> /usr/share/dict/british-english dictionary.txt grep -E
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 2/12 Selmner Selmner's almner almners calmness calmness's calmnesses $ grep -E 'lmn' dictionary.txt $ 2041 autotest dictionary Q1 Test Q1 (dictionary Q1) - passed 1 tests passed 0 tests failed grep -E $ grep -E -i '[aeiou]{4}' dictionary.txt $ 2041 autotest dictionary Q2 Test Q2 (dictionary Q2) - passed 1 tests passed 0 tests failed grep -E Aiea Aiea's Araguaia Araguaia's Douai Douai's Graeae Graiae abstemious abstemiously abstemiousness abstemiousness's abstemiousnesses abstentious adenocarcinomatous adventitious
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 3/12 $ grep -E -i 'a.*e.*i.*o.*u' dictionary.txt $ 2041 autotest dictionary Q3 Test Q3 (dictionary Q3) - passed 1 tests passed 0 tests failed grep -E abstemious abstemiously abstentious arsenious caesious facetious facetiously $ grep -E -i '^[^aeiou]*a[^aeiou]*e[^aeiou]*i[^aeiou]*o[^aeiou]*u[^aeiou]*$' dictionary.txt $ 2041 autotest dictionary Q4 Test Q4 (dictionary Q4) - passed 1 tests passed 0 tests failed autotest $ 2041 autotest dictionary give $ give cs2041 lab01_dictionary dictionary_answers.txt dictionary_answers.txt
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 4/12 This file is automarked. Do not add extra lines to this file, just add your answers. For example if your answer to Q0 is: "grep -E Andrew words.txt" Change the line that starts with "Q0 answer:" to "Q0 answer: grep -E Andrew words.txt" ---------------------------------------------------------------------------------------------------- -------------------- 1) Write an grep -E command that prints the words which contain the characters "lmn" consecutively. Q1 answer: grep -E 'lmn' dictionary.txt 2) Write an grep -E command that prints the words which contain any four consecutive vowels. Q2 answer: grep -E -i '[aeiou]{4}' dictionary.txt 3) Write an grep -E command that prints the words which contain all 5 vowels "aeiou" in that order. Q3 answer: grep -E -i 'a.*e.*i.*o.*u' dictionary.txt 4) Write an grep -E command that prints the words which contain the vowels "aeiou", in that order, and no other vowels. Q4 answer: grep -E -i '^[^aeiou]*a[^aeiou]*e[^aeiou]*i[^aeiou]*o[^aeiou]*u[^aeiou]*$' dictionary.txt parliament_answers.txt dictionary_answers.txt # Open a text editor (gedit) in the background (&) and not owned by the current terminal (disown) $ gedit parliament_answers.txt & disown # Or use any other text editor of your choosing parliament.txt parliament.txt grep -E Hon Scott Buchholz: Member for Wright, Queensland Hon Tony Burke: Member for Watson, New South Wales Mr Stephen Jones: Member for Whitlam, New South Wales Mr Peter Khalil: Member for Wills, Victoria Mr Llew O'Brien: Member for Wide Bay, Queensland Mr Dave Sharma: Member for Wentworth, New South Wales Ms Anne Stanley: Member for Werriwa, New South Wales Ms Zali Steggall OAM: Member for Warringah, New South Wales Hon Dan Tehan: Member for Wannon, Victoria
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 5/12 $ grep -E 'Member for W' parliament.txt $ 2041 autotest parliament Q1 Test Q1 (parliament Q1) - passed 1 tests passed 0 tests failed grep -E Hon Andrew Gee: Member for Calare, New South Wales Mr Andrew Giles: Member for Scullin, Victoria Hon Andrew Hastie: Member for Canning, Western Australia Hon Dr Andrew Leigh: Member for Fenner, Australian Capital Territory Hon Andrew Wallace: Member for Fisher, Queensland Mr Andrew Wilkie: Member for Clark, Tasmania $ grep -E '^((Mr|Mrs|Ms|Dr|Hon) )*Andrew .*:' parliament.txt $ grep -E ' Andrew .*:' parliament.txt $ 2041 autotest parliament Q2 Test Q2 (parliament Q2) - passed 1 tests passed 0 tests failed grep -E Ms Angie Bell: Member for Moncrieff, Queensland Mr Julian Hill: Member for Bruce, Victoria Mr Brian Mitchell: Member for Lyons, Tasmania Mr Rob Mitchell: Member for McEwen, Victoria Ms Zali Steggall OAM: Member for Warringah, New South Wales $ grep -E 'll( [A-Z]*)?:' parliament.txt $ grep -E 'll:' parliament.txt
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 6/12 $ 2041 autotest parliament Q3 Test Q3 (parliament Q3) - passed 1 tests passed 0 tests failed grep -E Ms Peta Murphy: Member for Dunkley, Victoria Mr Rowan Ramsey: Member for Grey, South Australia $ grep -E 'y( [A-Z]*)?:.*y,' parliament.txt $ grep -E 'y:.*y,' parliament.txt $ 2041 autotest parliament Q4 Test Q4 (parliament Q4) - passed 1 tests passed 0 tests failed grep -E Dr Anne Aly: Member for Cowan, Western Australia Hon Linda Burney: Member for Barton, New South Wales Mr Pat Conroy: Member for Shortland, New South Wales Mr Milton Dick: Member for Oxley, Queensland Hon Ed Husic: Member for Chifley, New South Wales Hon Bob Katter: Member for Kennedy, Queensland Ms Ged Kearney: Member for Cooper, Victoria Mr Craig Kelly: Member for Hughes, New South Wales Hon Michelle Landry: Member for Capricornia, Queensland Hon Sussan Ley: Member for Farrer, New South Wales Mrs Melissa McIntosh: Member for Lindsay, New South Wales Hon Ben Morton: Member for Tangney, Western Australia Ms Peta Murphy: Member for Dunkley, Victoria Mr Llew O'Brien: Member for Wide Bay, Queensland Hon Tanya Plibersek: Member for Sydney, New South Wales Mr Rowan Ramsey: Member for Grey, South Australia Ms Michelle Rowland: Member for Greenway, New South Wales Ms Anne Stanley: Member for Werriwa, New South Wales Ms Anika Wells: Member for Lilley, Queensland Mr Trent Zimmerman: Member for North Sydney, New South Wales $ grep -E 'y( [A-Z]*)?:|y,' parliament.txt
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 7/12 $ grep -E 'y[:,]' parliament.txt $ 2041 autotest parliament Q5 Test Q5 (parliament Q5) - passed 1 tests passed 0 tests failed grep -E Hon Josh Frydenberg: Member for Kooyong, Victoria Mr Luke Gosling OAM: Member for Solomon, Northern Territory Hon Andrew Hastie: Member for Canning, Western Australia Hon Catherine King: Member for Ballarat, Victoria Ms Madeleine King: Member for Brand, Western Australia Hon Bill Shorten: Member for Maribyrnong, Victoria Mr Terry Young: Member for Longman, Queensland $ grep -E 'ng[^a-z]' parliament.txt $ 2041 autotest parliament Q6 Test Q6 (parliament Q6) - passed 1 tests passed 0 tests failed grep -E Hon Anthony Albanese: Member for Grayndler, New South Wales $ grep -E '[AEIOU][^ ]*[aeiou]( [A-Z]*)?:' parliament.txt $ 2041 autotest parliament Q7 Test Q7 (parliament Q7) - passed 1 tests passed 0 tests failed grep -E
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 8/12 Hon Barnaby Joyce: Member for New England, New South Wales Ms Kristy McBain: Member for Eden-Monaro, New South Wales Mr Llew O'Brien: Member for Wide Bay, Queensland Hon Matt Thistlethwaite: Member for Kingsford Smith, New South Wales Hon Jason Wood: Member for La Trobe, Victoria Mr Trent Zimmerman: Member for North Sydney, New South Wales $ grep -E 'Member for [a-zA-Z]+[ -][a-zA-Z]' parliament.txt $ 2041 autotest parliament Q8 Test Q8 (parliament Q8) - passed 1 tests passed 0 tests failed autotest $ 2041 autotest parliament give $ give cs2041 lab01_parliament parliament_answers.txt parliament_answers.txt
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 9/12 This file is automarked. Do not add extra lines to this file, just add your answers. For example if your answer to Q0 is: "grep -E Andrew words.txt" Change the line that starts with "Q0 answer:" to "Q0 answer: grep -E Andrew words.txt" ---------------------------------------------------------------------------------------------------- -------------------- 1) Write a grep -E command that will print all the lines in the file where the electorate begins with 'W'. Q1 answer: grep -E 'Member for W' parliament.txt 2) Write a grep -E command that will print all the lines in the file where the MP's first name is "Andrew". Q2 answer: grep -E '^((Mr|Mrs|Ms|Dr|Hon) )*Andrew .*:' parliament.txt 3) Write a grep -E command that will print all the lines in the file where the MP's surname (last name) ends in the letters 'll'. Q3 answer: grep -E 'll( [A-Z]*)?:' parliament.txt 4) Write a grep -E command that will print all the lines in the file where the MP's name and the electorate ends in the letter 'y'. Q4 answer: grep -E 'y( [A-Z]*)?:.*y,' parliament.txt 5) Write a grep -E command that will print all the lines in the file where the MP's name or the electorate ends in the letter 'y'. Q5 answer: grep -E 'y( [A-Z]*)?:|y,' parliament.txt 6) Write a grep -E command that will print all the lines in the file where there is any word in the MP's name or the electorate name that ends in "ng". Q6 answer: grep -E 'ng[^a-z]' parliament.txt 7) Write a grep -E command that will print all the lines in the file where the MP's surname (last name) both begins and ends with a vowel. Q7 answer: grep -E '[AEIOU][^ ]*[aeiou]( [A-Z]*)?:' parliament.txt 8) Write a grep -E command that will print all the lines in the file where the electorate name contains multiple words (separated by spaces or hyphens). Q8 answer: grep -E 'Member for [a-zA-Z]+[ -][a-zA-Z]' parliament.txt ab_answers.txt dictionary_answers.txt # Open a text editor (gedit) in the background (&) and not owned by the current terminal (disown) $ gedit ab_answers.txt & disown # Or use any other text editor of your choosing grep -E
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 10/12 input.txt grep -E input.txt A B $ grep -E 'A.*B|B.*A' input.txt $ 2041 autotest ab Q1 Test Q1 (ab Q1) - passed 1 tests passed 0 tests failed grep -E input.txt A B A B B A $ grep -E '^(BA|A)*(BA|B)*$' input.txt $ 2041 autotest ab Q2 Test Q2 (ab Q2) - passed 1 tests passed 0 tests failed grep -E input.txt A B A 4
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 11/12 $ grep -E '^B*(AB*AB*AB*AB*)*$' input.txt $ 2041 autotest ab Q3 Test Q3 (ab Q3) - passed 1 tests passed 0 tests failed autotest $ 2041 autotest ab give $ give cs2041 lab01_ab ab_answers.txt ab_answers.txt This file is automarked. Do not add extra lines to this file, just add your answers. For example if your answer to Q0 is: "grep -E Andrew words.txt" Change the line that starts with "Q0 answer:" to "Q0 answer: grep -E Andrew words.txt" ---------------------------------------------------------------------------------------------------- -------------------- 1) Write a grep -E command that prints the lines in a file named input.txt containing at least one A and at least one B. Q1 answer: grep -E 'A.*B|B.*A' input.txt 2) Write a grep -E command that prints the lines in a file named input.txt containing only the characters A and B such that all pairs of adjacent A's occur before any pairs of adjacent B's. Q2 answer: grep -E '^(BA|A)*(BA|B)*$' input.txt 3) Write a grep -E command that prints the lines in a file named input.txt containing only the characters A and B such that the number of A's is divisible by 4. Q3 answer: grep -E '^B*(AB*AB*AB*AB*)*$' input.txt
01/09/2022, 11:14 COMP(2041|9044) 22T2 — Week 01 Laboratory Sample Solutions https://cgi.cse.unsw.edu.au/~cs2041/22T2/lab/01/answers 12/12 give give autotest autotest $ 2041 classrun -sturec
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help