Homework 3

Even more Unix shell

This assignment continues to practice using the bash shell and basics of combining commands using redirection and pipes. Submit your responses to Tasks 1, 2, and 3 to Gradescope.

Download the homework files on attu

After logging into attu, download the homework files.

git archive --remote=git@gitlab.cs.washington.edu:cse391/25wi/hw3.git --prefix=hw3/ HEAD | tar -x

Task 1: More vim navigation

In vim, open intro_survey CSV file for this quarter and answer the following questions in task1.txt.

  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?

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. We also recommend getting even more practice by writing the answers to your task1.txt, task2.sh, and task3.sh files using vim!

Task 2: More bash commands

For this task, we will compose shell commands with input/output redirection operators such as >, >>, <, |, &&, and ; to compare this quarter’s survey responses with last quarter’s survey responses. For each item below, determine a single bash statement that will either perform the operation(s) requested or answer the given question.

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

  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 this quarter’s survey data?
  2. We want to be able to analyze the combined results of the survey for both quarters. Write the command that will create a combined_results.csv file, containing the results from 24au, followed by the results from 24sp. The combined_results.csv file should only have the question titles appear once at the top of the file. Header titles should not appear again in the middle.
  3. Using the combined results, how many students responded with “anything” (case-insensitively) to any of the questions while also preferring cats over dogs? Assume that all responses in other columns do not contain commas.
  4. What are the three most popular candies (case-insensitively) from the combined results in order of popularity? Write a command that outputs for each unique candy: (a) 4 spaces followed by (b) a two digit count and (c) the name of the candy in any letter case. The leading 4 spaces should match the default behavior of one of the commands needed to solve this problem.
  5. Come up with your own question about the survey responses and answer it 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.

For the final creative problem, here is an unrelated question and solution to it. Your question should be about the survey responses.

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

Task 3: Developing the FAANG website

Welcome to your first day at FAANG, a budding startup. As a system administrator, your task is help some front-end developers keep the company website up-to-date. The hw3 directory contains a site directory with the contents of the company website. For this task, assume your working directory is the site directory.

For each item below, determine a single bash statement that will either perform the operation(s) requested or answer the given question.

  1. 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. Write a command to delete any subdirectories prefixed “dir” using find. Be sure to delete only subdirectories, not files like dirt.jpg. If you accidentally remove the wrong files, you can make a backup of your task* files and re-download the homework files on attu.
  2. Now that the old directories have been deleted, let’s 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 using the seq command, which prints a sequence of numbers. Be sure your approach is generalizable: it should be simple to change your code to create 100 directories.
  3. One of the 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 want your help accessing the output produced by CheckTransactions. Write a command that compiles CheckTransactions.java and, if it compiles successfully, runs CheckTransactions redirecting all output from standard error to err.log.