Due Tuesday 10/22 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.
To calculate your final score on this assignment, sum the individual scores from Gradescope.
- if your
score
is between[0, 1)
, you will get0
points - if your
score
is between[1.0, 1.5)
, you will get1
point - if your
score
is between[1.5, 2]
, you will get2
points
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/24au/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. You may need to redownload the hw2
directory if you don’t still have it:
wget https://courses.cs.washington.edu/courses/cse391/24au/homework/hw2/hw2.zip
unzip hw2.zip
- 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?
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
directory in the files intro_survey_24au.csv
and intro_survey_24sp.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
directory.
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 24au survey data?
Problem 2
We want to be able to analyze the combined results of the survey for both 24au and 24sp 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 have the header at the top but should not have the header from the intro_survey_24sp.csv
file in the middle.
Problem 3
How many students from both quarters who had “anything”, case-insensitively, in any of their responses also prefer cats? Your answer should assume that all responses in other columns DO NOT contain commas. This may not give you the true answer, refer to Lecture 3 Discussion Question 4 as to why that may be.
Problem 4: Challenge Question
What are the three most popular candies (case-insensitively) from the combined results 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
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
directory that contains the contents of the company website. You can assume you are inside the site
directory when doing these problems.
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, starting at the current working directory, will delete any subdirectories 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
.