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
.
- What is the command to cut or delete 5 lines of text, starting from your current cursor position?
- What is the command to paste the 5 lines of text you just cut in the previous question?
- 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.
- The
cut
command performs a similar operation as theParseColumn
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? - 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. Thecombined_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. - 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.
- 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.
- 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.
- 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” usingfind
. Be sure to delete only subdirectories, not files likedirt.jpg
. If you accidentally remove the wrong files, you can make a backup of yourtask*
files and re-download the homework files on attu. - 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 theseq
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. - 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 byCheckTransactions
. Write a command that compilesCheckTransactions.java
and, if it compiles successfully, runsCheckTransactions
redirecting all output from standard error toerr.log
.