1. Start in your home directory on an edlab machine (type ''cd'' to jump directly there)
cd cs197u to move into your course home directory.
cp -r /courses/cs100/cs197u/cs197u/assignments/assign-2/ . to copy the assignment directory into your course home directory.
(the "." in the cp command is important!)
4. Change into the newly copied ''assign-2'' directory.
pwd and verify that it says:
ls to verify that the directory contains 3 files.
vimto edit the file named
answers.txt. Fill in the answers to the questions in Part 1 as described in the file. There should be a list of nine commands to try, and one other question about head and tail. Note:
vimwindow open at the same time
vimregularly so you don't lose your work!
grepto search through a file and
sortto sort files alphabetically or numerically. The command
wc [file]is used to count the number of words, lines, or bytes in a file. Use
man wcto find out more about this command.
wc to find out how many lines are in the file
2.B) How many lines in the
romeoandjuliet.txt file contain the word "Romeo"?
2.C) What is the line number of the 100th line in the
romeoandjuliet.txt file that does not contain a comma? Write the line number, the line, and the command you use into
answers.txt. Hint: Find the flag for grep that displays the line number in the output. In your solution, the line number and the actual line from the file can be in the same output.
Next, we will analyze the file
utah.txt. This is a data file with three comma separated columns:
Population, Year, County name.
sort, and one other command we learned about to print out the five counties with the greatest population (in decreasing order) from the year 1969. Write the command you use into
answers.txt. Hint: the 5th most populous county should be "Cache", and you may need to give
sort 2 different flags.
2.E) Save the output from the previous command (using the
> symbol) to a file called
2.F) Read about the
cut command in
man and learn how to separate a column (or `field') from a file. Use
cut with 3 other commands to find out the unique number of counties that Utah has. Write the unique number of counties and the command you use into
I will collect the files
top-counties.txt directly from
/courses/cs100/cs197u/USERNAME/assign-2 . Make sure you followed the directions in part 0 so the files exist in the correct location.
To check this, use the following commands:
cd /courses/cs100/cs197u/USERNAME/assign-2, replacing USERNAME with your own