Starting from:

$30

CSE391 Assignment 2- More Unix Shell Solved 




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 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.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.​  

1.       What is the command to move your cursor to the end of the file?

2.       What is the command to move your cursor back up to the beginning of the file?

3.       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 it’s not required that you look this up, you may find it helpful.  

4.       What is the command to search for the text “chocolate”?

5.       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?”, “What's your favorite candy?”, and “What's 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.  

6.       Compile the Java program stored in the file ​ParseColumns.java.​  

7.       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 ​ParseColumns.class to select columns from ​             ​intro_survey.csv containing the answers to “What's​              your favorite candy?” and writing the output in a file called ​candies.txt. You may use ​     ​candies.txt for later​  problems.  

8.       Display all lines 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.  

9.       How many students responded to the survey with the exact response "​I don’t like candy"?​   

10.   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 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.

11.   How many students completed the survey?

12.   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.  

13.   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

XX  Cats 

XX Dogs 

XX Neither  

14.   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

XX  Candy1 

XX Candy2 XX Candy3

15.   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?  

 

More products