HW3 - Even More Unix Shell! (2 points)

Due Tuesday 04/18 at 1:00 pm. No late submissions accepted.

Submission: Gradescope

Specification: Spec


This assignment continues to practice using the bash shell and basics of combining commands using redirection and pipes. For Task 0 there is nothing to submit. For Tasks 1, 2, and 3 you will submit your responses to Gradescope.

Task 0: Log in and prepare a directory

First, log in to a machine running Linux and launch a Terminal window as described previously in Homework 1.

We have set up a ZIP archive full of support files that you must download to your Linux machine. Download/unzip it to a directory on your system.

wget https://courses.cs.washington.edu/courses/cse391/23sp/homework/hw3/hw3.zip
unzip hw3.zip

Task 1: Basic Navigation in a Text Editor

The following are exercises and questions are meant to help you become more comfortable with a text editor that is built into the command line. You can choose either vim or emacs. While the answers to the questions themselves are relatively easy to find by simply looking them up, the real learning will come from you actually practicing these commands yourself. While we won’t be able to know whether you’ve really been practicing, this is not for our benefit, it’s for yours. We also recommend getting even more practice by writing the answers to your task1.txt and task2.sh, task3.sh files using this editor. 😊

For all of these questions, you will be using the text editor of your choice to practice navigating around the intro_survey.csv file in the hw2 directory.

  1. What is the command to cut or delete 5 lines of text, starting from your current cursor position?
  2. What is the command to paste the 5 lines of text you just cut in the previous question?
  3. What is the command to copy 8 lines of text, starting from your current cursor position?

Task 2: Bash shell commands

For this task you will use shell commands to process the class’ responses to the introductory survey, as well as the previous quarter’s responses to the same introductory survey. The results are stored in the hw3 folder in the files intro_survey_23sp.csv and intro_survey_23wi.csv. Similar to last week, one of the goals of this assignment is to show you that a few simple commands can be used to process and analyze data.

For each item below, determine a single bash shell statement that will either perform the operation(s) requested or provide the answer to a question. Each solution must be a one-line shell statement, but you may use input/output redirection operators such as >, >>, <, |, &&, and ;. For all commands, do not create any files except those indicated. In response to each question, write the command that will perform the task described, not the output that the command produces. You can assume you are in the hw3 directory when doing these problems.

Write your answers in on the indicated lines in the task2.sh file in the hw3 folder.

Problem 1

The cut command performs a similar operation as the ParseColumn Java program from last week’s homework. What is the command to extract the column with the answers to “What’s your favorite candy?” from the 23sp survey data?

Problem 2

We want to be able to analyze the combined results of the survey for both 23sp and 23wi quarters. Write the command that will create a combined_results.csv file, containing the results from 23sp, followed by the results from 23wi. The combined_results.csv file should have the header at the top but should not have the header from the intro_survey_23wi.csv file in the middle.

Problem 3

How many students from both quarters who had “noodles”, case-insensitively, as part of their answer to “What’s your favorite dinner to make?” prefer cats?

Problem 4: Challenge Question

What are the three most popular candies (case-insensitively) from 23sp in order of popularity? Write the command that outputs the count along with the preference, for each preference, as in

    XX Candy1
    XX Candy2
    XX Candy3
Note the leading whitespace is required. This formatting is the default behavior of one of the commands needed to solve this problem.

Problem 5: Creative Question

Come up with your own question about the data from the intro survey that you would like to answer using any of the commands taught in the course so far. Write your question as a comment inside the function (comments begin with a #), then write your command, uncommented, beneath your comment on the following line.

For example, here is an unrelated question and solution to the problem at hand. Your question should be about the intro survey data.

function problem5 {
    # How many files are in this directory?
    ls | wc -l
}

Task 3: More bash shell commands; Developing the FAANG website

Welcome to your first day at FAANG! FAANG is a budding startup that, once it grows in popularity, will no longer reference Facebook, Apple, Amazon, Netflix Google but in fact this unicorn company. (The investors are sure of this.) You were hired to work on the system administration team, and the recruiter was particularly impressed by your knowledge of Linux. Your first day on the job will be helping some front-end developers getting the company website up to date.

The hw3 directory contains a site.zip file that contains the contents of the company website. Unzip the site.zip to create a site directory. You can assume you are inside the site directory when doing these problems.

For this task, you can work from the VM or copy the site directory to your local machine so that you can view the contents of the website in a web browser. You may find this helpful, although it is not required. To do so, from a file browser either double-click on site/index.html and it should automatically open in a web browser. You can also right click on site/index.html, select Open With > your favorite web browser.

For each item below, determine a single bash shell statement that will either perform the operation(s) requested or provide the answer to a question. Each solution must be a one-line shell statement, but you may use input/output redirection operators such as >, >>, <, |, &&, and ;. For all commands, do not create any files except those indicated. In response to each question, write the command that will perform the task described, not the output that the command produces.

Problem 6

The old web development team had different subdirectories for each product that the company makes named dir1, dir2, …, dir10, etc. These directories are no longer wanted and should be deleted to save space on the server. Write a command that will delete all directories that are prefixed with “dir”.

You will want to read the man pages for find to find only files that are directories. Your function should be generic and not specific to the directories inside of the zip you are provided. As a reminder, if you accidentally remove the wrong files you can re-download hw3.zip from the course website.

Problem 7

Now that the old directories have been deleted, it is time to create new directories. There will be one directory for each product simply named 1, 2, 3, etc. Write a command to create directories 1 through 9.

You may find the seq command, which prints a sequence of numbers helpful. Note, your function should be generic and should not simply enumerate the directories needed to be created using && or ;. In other words, it should be a simple change to your solution for us to change this problem to create 100 directories.

Problem 8

One of the backend developers wrote a program called CheckTransactions that outputs information about transactions made recently on the website. There seems to be a bug with the site, however, and they are having trouble locating it. The developer thinks it would be useful if all of the transactions which produced errors were printed to a separate file. Write a command that compiles CheckTransactions.java, and if it compiles successfully, runs CheckTransactions and redirects all output from standard error to a file named err.log.