Due date: Tuesday, Nov 7, 5:00am
Late policy:
After | and before | you get |
5:00am Tuesday. Nov 7 | 100% of the grade | |
5:01 am Tuesday. Nov 7 | 5:00 am Wednesday, Nov 8 | 98% of the grade |
5:01 am Wednesday, Nov 8 | 5:00 am Thursday, Nov 9 | 95% of the grade |
5:01 am Thursday, Nov 9 | 5:00 am Friday, Nov 10 | 90% of the grade |
5:01 am Friday, Nov 10 | 5:00 am Monday, Nov 13 | 80% of the grade |
5:01 am Monday, Nov 13 | 5:00 am Tuesday, Nov 14 | 50% of the grade |
5:01 am Tuesday, Nov 14 | nothing |
Please read all the instructions carefully. Remember, everything is case-sensitive!
You must 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:
(0 points) Create a cs114-HW4 subdirectory in your home directory and make sure you are the only one who has any access to it.
(0 points) You may want to review the man pages of the following programs: sh, test, wc, sort, head, cat, gawk, mkdir, find, cmp. expr
In this homework you are allowed to use any utilities you are familiar with.
Warning: I will run your programs (scripts) in my own environment. This environment may contain unusual setting for some common variables, such as PATH environment variable. Your script should tolerate any unusual environments.
Warning: Your programs should still work correctly when some arguments and/or environment variables contain special symbols (you will still get partial credit if you fail the "special symbols" test).
Your programs should not modify any files except for those that you are explicitly instructed to modify. This includes not creating any temporary files.
Your program should consist of a single file and not invoke other "external" scripts.
Testing your scripts is part of the homework. While examples I provide may be useful as test cases, their primary purpose is to help you understand the homework requirements. You should try to come up with your own test cases.
(3 points) Write a program (hint: an awk script) ~/cs114-HW4/part1 that prints two copies (one right after another) of each line it receives on its standard input.
Example: ~/cs114-HW4/part1 < ~cs114/ex/HW4-1 should produce the following output:
ABC ABC 10 10 0 0 50A 50A
To submit part I, run ~cs114/bin/grade-hw4-1. Expect a confirmation e-mail after each submission. The grade you receive will be the maximum of the grades you receive for the first two submissions.
The idea behind this part of the homework is to create a utility capable of doing a subset of homework 1. When a script is ran with arguments dir1 dir2 file it will create dir2, then look for a file under dir1 and copy it to dir2. My hints assume that you will be writing a shell script, but you can use something else if you want.
Write a program (for example, /bin/sh script) ~/cs114-HW4/part2 that does the following in the specified order:
Example: running ~/cs114-HW4/part2 ~cs114/HW1 ~/cs114-HW1/A/B/C file3 should solve part of the first homework by copying ~cs114/HW1/subdir/.../--/file3 to ~/cs114-HW1/A/B/C/file3.
To submit part II, run ~cs114/bin/grade-hw4-2. Expect a confirmation e-mail after each submission. The grade you receive will be the maximum of the grades you receive for the first three submissions.
(3 points) What will the following scripts do (explain how their output depends on the input)
#!/usr/local/gnu/bin/gawk -f BEGIN {FS="\|"} (NF>0) {total+=(NF-1)} END {print total}
#!/bin/sh echo `tr -cd "|" | wc -c`
(2 point) Explain why the echo `...` construction is necessary in the second script (try replacing the second line with simply tr -cd "|" | wc -c). Explain how that works.
To submit Part III, use ~cs114/bin/pine on babbage. Send an e-mail to cs114@cs.cornell.edu with the subject HW4 containing answers to the questions 1-2. Expect the confirmation e-mail. Only the first submission will be graded.
Let's grade HW2. The idea is to write a program such that ~/cs114-HW4/part4 dir1 dir2 would grade the solution in dir2 provided that dir1 has a correct solution.
Write ~/cs114-HW4/part4 that does the following in the following order:
Example: If you haven't deleted HW2 files from ~/cs114-HW2, then ~/cs114-HW4/part4 ~/cs114-HW2 ~/cs114-HW2 should print number 3.
To submit part IV, run ~cs114/bin/grade-hw4-4. Expect a confirmation e-mail after each submission. The grade you receive will be the maximum of the grades you receive for the first three submissions.