Due Tuesday 01/18 at 1:00 pm. No late submissions accepted.
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 and 2 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/22wi/homework/hw2/hw2.zip unzip hw2.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
task2.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
- What is the command to move your cursor to the end of the file?
- What is the command to move your cursor back up to the beginning of the file?
- What is the command move to line 50 of the file? Practice moving around to different lines in the file. You may notice that emacs and vim do not show line numbers of a file by default but you can enable line numbers. While it’s not required that you look this up, you may find it helpful.
- What is the command to search for the text “chocolate”?
- What is the command to go to the next match from your search?
Task 2: Bash shell commands¶
For this task you will use shell commands to process the class’ responses to the introductory survey completed last week. The results are stored in the
hw2 folder in a file called
intro_survey.csv. As you may notice, only four of the questions from the survey have been included: “What’s your favorite candy?”, “What’s your favorite dinner to make?”, “Cats or Dogs?” and “Are you currently enrolled in CSE 351?” 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
|. For all commands, do not create any files except those indicated.
To test your commands, you should have unzipped
hw2.zip into the current directory. You can assume you are in the
hw2 directory when doing these problems.
Write your answers in on the indicated lines in the
task2.sh file in the
Compile the Java program stored in the file
ParseColumn Java program takes a column number (1-indexed) as a command-line argument, reads a CSV file from
stdin line by line and outputs the data from the specified column only. Run the Java
ParseColumn program stored in
ParseColumn.java to select columns from
intro_survey.csv containing the answers to “What’s your favorite candy?” and write the output to a file called
You may use the resulting
candies.txt file for later problems.
Display each of the responses from
candies.txt that contain the text
"chocolate", ignoring case. That is, all of the favorite candies that have chocolate as part of the response.
Display each of the responses from candies.txt that DO NOT contain the text
"chocolate", ignoring case.
Don’t worry about removing the header “What’s your favorite candy?” from the output.
Create a new file called
intro_survey_no_header.csv containing the entire contents of the original
intro_survey.csv file, without the header. (The header is the first line in the file containing the survey questions.) Note your command should be flexible, regardless of the specific number of lines in the
man pages for the
tail commands for help on how to do this.
You may use the resulting
intro_survey_no_header.csv file for later problems.
How many students completed the survey?
Assuming that the intro survey lists responses in chronological order, what was the favorite dinner of the last person to turn in the survey?
How many students in the course are not also taking CSE 351? Note that because the answers to the question “Are you currently enrolled in CSE 351?” are “Yes” and “No”, you won’t be able to simply
intro_survey.csv for “No”, as this word may appear as part of answers to other questions.
How many unique answers were there to question “What’s your favorite candy?” case-insensitively? Don’t worry right now about the difference between answers like “kit kat” and “kitkat”, but your solution SHOULD correctly count “kitkat” and “KITKAT” as the same.
This time you should be careful that the header “What’s your favorite candy?” is not counted.