Homework 2

Due date: Friday, October 13 at noon

Late policy:
Afterand beforeyou get
 noon on Friday, October 13100% of the grade
12:01 pm on Friday, October 135:00 am on Saturday, October 1480% of the grade
5:01 am on Saturday, October 145:00 am on Monday, October 1650% of the grade
5:01 am on Monday, October 16 nothing

This homework will be graded out of 15 points. Future homeworks may "cost" more.

Please read all the instructions carefully. Remember, everything is case-sensitive!

Getting Help and Academic Integrity

You should do all the work on your own without asking for any assistance from other people and without helping other students. In case you need help, you should,

  1. Take a look at the man pages, lecture notes and suggested reading.
  2. Go to cornell.class.cs114 newsgroup and see if your question is already answered. If not, post it there. I will be happy to answer any questions posted to the newsgroup, not necessarily HW-related.
  3. If you want to keep your question private, e-mail me at nogin@cs.cornell.edu. Please use newsgroup whenever possible. Questions posted to the newsgroup will be answered much sooner.

Setup (1 point)

(1) (1 point) Create a subdirectory cs114-HW2 in your home directory. Make sure you are the only one who has any kind of access permissions to it.

(2) (0 points) Go to ~cs114/HW2 directory. It has a subdirectory set up for each of the CS114 students. Copy all the files from ~cs114/HW2/your_netid to your cs114-HW2 directory. (In case you are wondering - these files contain lines semi-randomly picked from a bunch of man pages).

VI (7 points)

For problems (3-5) use vi, vim or ~cs114/bin/vim. Some of these problems are quite tricky, so triple-check your results. You may find diff utility useful for checking what happened.

(3) (2 points) In file1, prepend your Net-ID (your login) and a space to lines 10 trough 350. For example, if I would be doing this HW, then I would change the line
ayn2 xyz
Hint: Use VI substitution command.

(4) (2 points) In file2, replace each lower-case letter that go before r in the alphabet (excluding r itself) with two symbols \/.
Example:: 12abcrs5dA should become 12\/\/\/rs5\/A.

(5) (3 points) In file3, change all the lines that contain at least 2 | symbols in the following way:

Try doing all of this using a single substitution command.
Example: |qWe|rtY| should become |a QWE z|rtY|

grep (7 points)

(6) (0 points) Using man command on babbage, read the grep man page and find out, how to tell it to count the number of matches.

(7) (0 points) Create a file named answer in your cs114-HW2 directory.

(8) (3 points) Count the number of lines in file4 that have at least 3 occurences of some 2-character string (each line can have its own 2-character string). Put this number on the first line of the answer file (don't put anything else onto that line).
Example: qw1~wt1~aaass1~xce should be counted because 1~ appears 3 times.

(9) (1 point) Same as (8), but when the first of the two symbols in that string is not a lower-case a. Write the number in the second line of the answer file.

(10) (3 points) In the file5, count the number of lines that either

Put this number on the third line of the answer file.
Warning: none of the versions of egrep installed on babbage recognizes the {...} construction.

To submit your HW, run ~cs114/bin/grade-hw2. The script will work as many times as you run it, but you will only receive credit for your first submission. If something goes wrong, please let me know ASAP.