CSCI 344
Quiz 1
Wednesday September 24
You may use the web to search for reference material.
Write the answers in an ascii text file called quiz1. Copy your quiz1 file to the directory:
/user/projects/csci344/quizN/USERNAME
where N is the quiz number and USERNAME is your ecst username.
Put your name at the top of your answer file.
1) Assume the shell's path does not include the directory /usr/sbin.
What command could you type at the command prompt to modify the
path so it includes /usr/sbin while continuing to include all the directories it current
includes?
2) Show how grep can be used to search the dictionary /usr/share/dict/words for all words that:
a) start with ch
b) end with ch
c) have ch in the middle but don't start with ch or end with ch
d) contain an ei that is not after a c and not at the beginning or end of the word
3) Write a sed script that replaces all occurances of
if (...) {
with
if (...)
{
and
for(...) {
with
for(...)
{
Assume that ... stands for some string and the the entire if or for
(that is "if (...) {", and "for (...) {") is on one line. Also
assume that the line may or may not contain spaces. Your script
should perserve the spacing.
4) Write an awk script that takes a file with four fields and creates
four files each with one of the fields. Name the files file1,
file2, file3, file4.
For example running the scrip on the following file:
a b c d
e f g h
would create the following four files:
file1:
a
e
file2:
b
f
file3:
c
g
file4:
d
h
5) Write an awk script that takes a file containing zero or more records of the following form:
last name, first name, value1, value2, value3
last name, first name, value 1, value2, value3, value4
Each record will contain a last name, a first name, and zero or more
integer values. You can assume that there are no errors in the file (e.g.
no extra commas or values that are not integers). In a given file
not all records will have the same number
of values.
The output of the script should be:
last name, first name, average
last name, first name, average
....
average
Where the average after the names is the average of values for that
record (use 0 if there were no values) and the last average is the
average of all the averages (not the average of all the values).