Some parts of this assignment depend on compiling and running Java programs from the command line. Many distributions of Linux do not include Suns Java Development Kit (JDK). You may need to install JDK or use a different Linux machine that already has JDK installed, such as the CSE Virtual Machine (VM), CSE basement lab machines or the shared attu server. See the course web site for directions about how to install JDK on your own Linux machine.
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. We suggest creating a hw2 directory for your files for this assignment.
wget http://courses.cs.washington.edu/courses/cse391/19au/homework/2/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 wont be able to know whether youve really been practicing, this is not for our benefit, its for yours. We also recommend getting even more practice by writing the answers to your task1.sh and 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 hw2 directory.
- 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. While its 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 three of the questions from the survey have been included: Cats or Dogs?, Whats your favorite candy?, and Whats your favorite restaurant on the ave? 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.
(Continued on next page)
1 of 2
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 hw2 folder.
- Compile the Java program stored in the file java.
- The ParseColumns java program takes a column number (0-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 ParseColumns program stored in class to select columns from intro_survey.csv containing the answers to Whats your favorite candy? and writing the output in a file called candies.txt. You may use candies.txt for later problems.
- Display all lines from txt that contain the text chocolate ignoring case. That is, all of the favorite candies that have chocolate as part of the response.
- How many students responded to the survey with the exact response I dont like candy?
- Create a new file called 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 intro_survey.csv file. man the head/tail commands for help on how to do this. You may use intro_survey_no_header.csv for future questions.
- How many students completed the survey?
- Assuming that the intro survey lists responses in chronological order, what was the favorite restaurant of the last person to turn in the survey? While the provided java program outputted select columns from a file, you should use the cut command shown in lecture to perform a similar operation to select just the column that contains the restaurants.
- How many students prefer Cats? Prefer Dogs? Prefer neither? Write the command that outputs the count along with the preference, for each preference, as in
- Cats
XX Dogs
XX Neither
- Challenge question: What are the three most popular candies (case-insensitively) in the class in order of popularity? Similar to the previous question, your command should output the count as well as the names of the candies, as in
- Candy1
XX Candy2 XX Candy3
- 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. What is your question that you are answering and what is the command used to answer your question?
Reviews
There are no reviews yet.