CSCI 3294 (Unix Power Tools), Spring 2008:
Homework 5
- Assigned:
- February 27, 2008.
- Due:
- March 5, 2008, at 5pm.
- Credit:
- 20 points.
Read about the following topics
in the list of suggested readings,
either in one of the suggested readings or
in another book or reference.
(These are the topics for February 27):
Answer the following questions. You may write out your answers by
hand or using a word processor or other program, but please submit
hard copy, either in class or in my mailbox in the department office.
Answers to most questions will involve experimentation on
a UNIX or Linux system.
You are free to use any appropriate system
(unless a specific problem says otherwise);
if you use something other than Fedora Core Linux please tell me what.
- (4 points)
Write a grep command to search all the files
in the current directory for lines containing either
your Linux username (e.g., bmassing) or
your last name.
(You don't have to
also search subdirectories, just files in the current
directory itself.)
- (4 points)
Write a grep command to search all files in the
current directory for strings that could be Social Security
numbers (strings of the form nnn-nn-nnnn, where
each n is a decimal digit).
- (4 points)
Suppose you have a Java program in file Foo.java
containing the not-very-well-named variable Bar,
and you want to change this variable to bar
everywhere it occurs, without changing other occurrences
of the string Bar (such as myBar or
BarFoo).
Write a sed command that makes this change.
(Note that essentially the same command
would work in vim.) Don't worry about saving the
output back into the file; the point here is the command
to make the change.
- (8 points)
Suppose you have a text file (call it foo)
containing a list of names and e-mail addresses.
Each line contains first an e-mail address
(which for simplicity we'll define as
any combination of letters, digits,
and periods, followed by a @, followed by
any combination of letters, digits, and periods),
then some delimiter (a space, a colon, a comma -
anything that can't be part of the address as we
defined it), and then a name.
Write a sed command to reverse the addresses
and names, removing the delimiters and leaving at least
one space between the name and the address.
For example,
``me@mail.com: This Is Me!'' would be
changed to ``This Is Me! me@mail.com''.
(Hint: Backreferences may be useful.)
Again, don't worry about saving the changes back to
the file.
Also don't worry about what happens to lines that
don't have the form described (e.g., no e-mail address),
or about pruning out extra spaces.
Berna Massingill
2008-02-27