✍️ Get Writing Help
WhatsApp

HW 02 – RegEx and Filters

HW 02 – RegEx and Filters

AssignmentTutorOnline

50 HW points possible

Introduction

This homework assignment will measure what you have learned from the lecture and ensure practice through a series of simple tasks. Each task must be completed on its own and should be completed in a separate script file. You will also need to create the input files yourself with the data given in the lab document for that question. This can be done by simply copying and pasting the data. In order to be graded for credit,  each task must follow the naming convention below.

hw02-task##-ASURITE.sh

Where ## is the 2-digit task number and ASURITE is your username in all lowercase letters. For example, a student with username sdevil completing task 03 would create a file named:

hw02-task03-sdevil.sh

Throughout the document, the execution may be shown using the filename script.sh. This is only for illustrative purposes to reduce the amount of unnecessary data. Unless otherwise specified, your script file will be tested on our system with the following command:

bash ./hw02-task**-sdevil.sh

Please ensure that your script file returns the desired output when executed with this command and submit all of your script files to the respective assignment submission on Canvas. Please submit your .sh files directly, avoid zipping them or submitting any other archived format.  

Task 00 (0 points)

Use the man command to look up and read through the man pages for each of the following commands:

  • man
  • cat
  • echo
  • grep
  • wc
  • cut
  • uniq
  • head
  • tail 
  • sed

These are the commands that you will use to complete the following tasks for this homework. Remember that as an IT professional, you will often not have all the solutions in front of you. Research the commands and figure out how to use them to complete the tasks in this assignment.

As much as I admire please only use these commands to complete the homework and try to keep it as simple as possible. (That means no using Awk!)

Task 01 (5 points)

Use echo and cut to read in the given input string and output the expected output string.

Input string Expected output of script
All that is solid melts into air, all that is holy is profaned, and man is at last compelled to face with sober senses his real conditions of life and his relations with his kind. that man is sober and kind.

Task 02 (5 points)

Use tr to fix the following quote

Input file (hw0202.txt) Expected output of script
H e$was$a$sk ater$b%y$She$sa id$See$ya$l ater$b%y$H e$wa snt$go%d$e n%ug h$f%r$he r$Sh e$h ad$a$pret ty$fa ce$b ut$h er$h ead$w as$up$i n$spa ce$She$ne eded$t%$c ome$ba ck$d%w n$t%$ea rth He was a skater boy She said See ya later boy He wasnt good enough for her She had a pretty face but her head was up in space She needed to come back down to earth

Task 03 (5 points)

Use cut to extract the 5th word from the following string

Input file (hw0203.txt) Expected output of script
Those%who$believe:in*[email protected]?my#hand. telekinetics

Task 04 (5 points)

Write a piped command to count the number of unique words in the following input.

Input file (hw0204.txt) Expected output of script
Oh yeah, I’ll tell you something                         I think you’ll understand When I say that something I wanna hold your hand I wanna hold your hand I wanna hold your hand Oh please, say to me You’ll let me be your man And please, say to me You’ll let me hold your hand You’ll let me hold your hand I wanna hold your hand 25

Note: Look over your slides if you need help!

Task 05 (5 points)

Write a piped command to count the number of times the word “hand” occurs in the following input

Input file (hw0204.txt) Expected output of script
Oh yeah, I’ll tell you something                         I think you’ll understand When I say that something I wanna hold your hand I wanna hold your hand I wanna hold your hand Oh please, say to me You’ll let me be your man And please, say to me You’ll let me hold your hand You’ll let me hold your hand I wanna hold your hand 6 hand

Task 06 (5 points)

Write a single RegEx to match the lines that access port 22 and only those packets

Input file (hw0206.txt) Expected output of script
date time protocol ip-address port packet-size 2022-02-21 19:22:19 TCP 22.101.2.24 22 24   2018-22-22 02:25:12 UDP 10.221.7.22 2135 222 2200-05-22 22:26:22 UDP 22.122.6.62 2160 22 2012-22-20 15:43:22 TCP 10.121.7.222 22 122   1228-02-10 02:22:02 UDP 22.102.2.62 2089 22 22.101.2.24 10.121.7.222

Task 07 (5 points)

Write a single RegEx to match all of the items that you have enough rupees for

Input file (hw0207.txt) Expected output of script
item cost lamp oil 5 rope 10 bombs 20 lamp oil 5 rope 10

Note: You only have 12 rupees, if you want to buy anything more you’ll need to be a little richer

Task 08 (5 points)

Write a single RegEx to match every date except my dog’s birthday

Input file (hw0208.txt) Expected output of script
1991 January 25 1993 February 28 1994 December 21 1995 May 17 1996 January 30 1999 June 14 2002 August 6 2005 July 19 2009 August 5 2010 August 24 1991 January 25 1993 February 28 1994 December 21 1995 May 17 1996 January 30 1999 June 14 2002 August 6 2009 August 5 2010 August 24

Task 09 (5 points)

Write a love poem with sed

Input file (hw0209.txt) Expected output of script
Roses are red Roses are yellow Violets are violet My dog is violet Violets are blue Sugar is bad for you Sugar is violet Sugar is sweet Garlic bread I have the flu You were my brother, Anakin I loved you And so are you And you are blue Blink-182 And who are you Roses are red Violets are blue Sugar is sweet And so are you

Task 10 (5 points)

Write a single regular expression to return the email address of your instructor and grader.

Input file (hw0210.txt) Expected output of script
[email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

For faster services, inquiry about  new assignments submission or  follow ups on your assignments please text us/call us on +1 (251) 265-5102