Lab Awk / Sed / RegEx
Begin by downloading this file to scratch (use
For each task, you should start with the downloaded file and use
awk to parse the file. Everything should be done as a single command (without using intermediate files, or
&&). You probably will always use the pipe
| or multiple pipes.
Create a directory in your $HOME called labAwkSed. This directory will contain out1.txt - out13.txt when completed. There is an autograder for this lab.
For all examples I have listed only the first 3 lines of the new output but your files should contain all of the output.
Print out only the hostnames and redirect the output to out1.txt.
dickson robinson niven
Using awk and sort, print out the hostnames in alphabetical order and redirect the output to out2.txt.
adams anson asimov
Print out the string port ‘port number’ is attached to host ‘hostname’. (Make sure it is pulling hostname and port from the file) and redirect the output to out3.txt
port Gi6/37 is attached to host dickson port Gi6/38 is attached to host robinson port Gi6/47 is attached to host niven
Print out only the mac addresses. (Hint: I used
awkto remove the semicolon.) and redirect the output to out4.txt.
10:dd:b1:db:db:2d c8:2a:14:3f:9d:41 c8:2a:14:3f:a8:e0
Print the file in the following format and redirect the output to out5.txt.
dickson 18.104.22.168 robinson 22.214.171.124 niven 126.96.36.199
Now reverse and print out the ip’s:(note that 188.8.131.52 in reverse would be 184.108.40.206) and redirect the output to out6.txt. (Hint: awk to split on whitespace, awk to split on ‘;’, awk to split on ‘.’. Don’t forget to add the ‘.’ back in.)
220.127.116.11 253.195.38.144 249.195.38.144
Do the exact same as the last one, except instead of printing the ip with the ‘.’s in between, add the numbers up and redirect the output to out7.txt.
616 630 626 625
Use sed. Use the same downloaded file for Part II.
Print every other line in the file and redirect the output to out8.txt.
Delete the first line from the file and redirect the output to out9.txt.
Replace every occurance of the word ‘host’ with ‘computer’ and redirect the output to out10.txt.
Print only the 5-8th lines and redirect the output to out11.txt.
Remove the # and everything that follows from each line (use regular expression and sed search/replace) and redirect the output to out12.txt.
Print only lines 20-30 from the file and only the second and eighth columns, remove the semicolon. Search for and replace the ‘24’ and everything that comes before it with ‘removed’. Redirect the output to out13.txt.
card 18.104.22.168 decamp 22.214.171.124 clarke 126.96.36.199 dahl 188.8.131.52 crichton 184.108.40.206 burroughs 220.127.116.11 removed0 removed1 removed7
Run the autograder with
grade_labAwkSed. Submit a screenshot of the autograder.
Last Updated 11/06/2019