Unix Utilities Exercise
Changing the file named
.bash_profile
if you have not done so.
.. vi .bash_profile
(once inside the file …
make the following modification if you have not done so ..)
PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/bin:.
(save the file afterward … in order for this
profile to take effect, one needs to log off and log back in.)
The following is one way
to use the grep
command/utility.
1a. Change into your home directory.
1b. Create a file named
phonebook. Use the tab key for spacing.
John
777-1234
Ross
666-1212
Robert
712-3456
Cissy
772-5678
2.Create a new shell
script file named lu (e.g lookup) for looking up the phonebook.
# look someone up in
the phonebook
grep $1 phonebook
3.Create a new shell script file named add to add a
new employee to the phonebook. Although it is not visible to the naked eye,
there is a tab character between $1 and $2 in this shell script.
# add someone to the
phonebook
echo “$1 $2”
>> phonebook
4.Create a new shell script name remove to remove
someone from the phonebook.
# remove an employee from the phonebook
grep –v “$1” phonebook > oldphonebook
mv oldphonebook phonebook
|