Home
| |
Assignment 7 - UNIX - Section 040
This assignment is Assignment 7 for Section 040 - Ian Allen.
Hand in: The telnet log sheet from the
last Hand In step in hard copy form.
Preparations:
You must understand Section 5.3, Chapter 14 (Week 13), and
Chapter 15 (Week 14) to do this assignment.
Step 1. (Readings in Chapter 14 and 15)
Use vi to create an answer file named c14+15answers containing answers to the following
questions listed in the Week 13 (Chapter 14) and Week 14 (Chapter 15) Reading
Exercises. Put your name on the first line of the file. Answer
only the following questions:
- Answers to the Chapter 14 Reading Questions 14-4 through 14-6, 14-8, and
14-12.
- Answers to the Chapter 15 Reading Questions 15-5 through 15-9.
Make sure that your name is located at the top of the file.
Step 2. (Based on Chapter 14)
- Create the regexp file (pp.619-620 of
the text) and practice issuing the following commands. Pay extremely
close attention to the command name and quoting used, and to the exact
characters inside the single quotes.
grep '^the' regexp
grep 'that\$' regexp
grep '[^a-z]' regexp
grep '[^0-9]' regexp
grep -v '\^' regexp
grep -v '.' regexp
Step 3. (Based on Chapter 14)
- Create the text-extend file (p.642 of
the text) and practice issuing the following commands. Pay
extremely close attention to the command name and quoting used, and to the
exact characters inside the single quotes.
egrep 'xY+' text-extend
egrep '0(xY)+' text-extend
egrep 'xy*' text-extend
Step 4. (Based on Chapter 14)
Suppose that Kathy has a directory called Recipes
in which she stores more than 200 recipes, one recipe per file. Each recipe
contains information about the ingredients that were used, the cooking time,
etc. She would like to identify the recipe file names of all the
recipes that use wine as an ingredient.
- What command would you advise her to use? (The output that the
command would generate must be just a list of file names of the files
that contain the selected ingredient.)
- What command line could she use to have a count of the total number
of the recipe files found printed at the same time? (The command line
would generate both the file names and the count.)
Step 5. (Based on Section 5.3)
The wildcard pathname pattern matching abilities of the Unix shells differ
from that of grep, egrep,
and sed in that the shells do not
use regular expressions to match pathnames. Shell pathname wildcards are
often called "globbing" to distinguish them from
regular expressions.
A sample of Kathy's recipe file names is listed below:
eggplant.cacciatore
eggplant.divan
pot.au.feu
hearty.bean.soup
split.pea.soup
soup.supreme
caribbean.eggplant
hot.apple.sandwich
Create a recipe directory and create these empty files with the touch command. (If you're clever about it, and
you really know your Unix commands, you will be able to copy the above list of
names from this web page, paste it into a file, and use that file in a Unix
command to create all the empty files without typing each one in
individually.)
Creating the above directory of file names allows you to test the following
commands about globbing and file names:
- She would like to list only the soup
recipe file names. Type a Unix command that does this.
- Type a Unix command that lists only those file names that have soup as the last word.
- Type a single command line that lists the file names of all the eggplant and apple
recipes.
Step 6. (Based on Chapter 15)
- Create the gdbase file (pp.651-2 in the
text), the add-item file (p.662), and the
comment.file (p.664), and then issue the
following commands lines:
sed -e 's/Hshld/HSHLD/g' gdbase
sed -e '/Cheese/s/Dairy/Deli/g' gdbase
sed -e '7,/Fish/s/Meat/Animal/' gdbase
sed -f add_item gdbase
sed -e '/Fish/r comment.file' gdbase
As explained on p.661, the use of "-e"
to signal the argument containing the instructions to be executed is optional
when only one action is being performed.
Hand In:
Use telnet logging to record the following
session on your A: diskette. Perform only
the following actions, in the following order. When asked to display the
contents a file or script, use the cat
command. (Do not use an editor or the commands that paginate the file,
since the pagination mis-formats the display of the file in the log.)
- Display your USER environmental
variable. (Only the one variable, not the whole environment!)
- Display the date.
- Set your shell prompt to be the current working directory.
- Display the c14+15answers file created
in Step 1.
- Display the contents of the regexp file
of Step 2.
- Execute the six commands of Step 2.
- Display the contents of the text-extend
file of Step 3.
- Execute the three commands of Step 3.
- Use two echo commands to echo onto your screen the answers to the two
questions in Step 4.
- Enter the directory you created in Step 5. Show all the file and
directory names in this directory, including hidden files.
- Execute the three commands of Step 5.
- Enter the directory that contains the three files used in Step 6.
- Display the contents of the gdbase
file.
- Display the contents of the add-item
file
- Display the contents of the comment.file
file.
- Execute the five commands of Step 6.
- Display the date again.
- Stop logging and print the telnet log
file for handing in. This one log file is the only thing you should
hand in.
|