Starting from:
$30

$24

Lab 1b: Unix Commands Solution

What To Do




Part 1: Regex




In this lab, you will practice Unix commands and writing regular expressions. If you do not remember which Unix command to use, you can look at the slides on Canvas (​bash scripting​, regular expressions​). You can also use the man pages, trial and error (but be careful), and your favorite search engine to complete the lab.




Step 1.​Again, you have the option to work with a partner. If you or your partner do not have a Linux or Mac system you can use the CU’s online coding environment, ​here​.




Step 2.​Create a file called “lab1b.txt”. Write your and your partner’s name at the top of the file.

You will record each of the commands you used during this activity in this file.




Step 3.​Download the Lab1b.zip folder ​here​and copy it to your home directory. Decompress it using the unzip command. You will be using the files inside the Lab1b folder:




password_demo.txt



grades.txt



cryptic.txt



Step 4.​Complete the following exercises. Make sure to record the commands:




Using the ​wc​command:

Find the number of lines in “password_demo.txt”



Find the number of characters in “password_demo.txt”



Using the ​cut​command

Print a list of usernames from “password_demo.txt” (print the first column only)



Print out only LN column and HW1 column from “grades.txt”



Using pipes

Use the cut, sort, and uniq command to print out the user groups within



password_demo.txt (Each user group is a number. When printing, each group should be on a new line and there should be no duplicates)




Pipe the output from above to a file called “user_groups.txt”



Use grep and cut to filter the “password_demo.txt” file to display usernames that start with ‘m’, ‘w’, or ‘s’



Using the ​awk​command:

Using “grades.txt”, print out the first and last names of each student and print their average grade (columns HW1, HW1, HW3, L1, L2, and L3).
Using “grades.txt” print the class average for the lab assignment (columns L1, L2, and L3).



Using the ​sed​command:

Remove all the letters from the “cryptic.txt” file. You’ll need to use regular expressions.



Replace all the numbers with an ‘_’. You’ll need to use regular expressions.









What To Turn In




EACH student should submit their lab1b.txt file to Canvas. If you worked with a partner, your lab1b.txt will be identically.

More products