Linux Shell Script

Project 3

1. Using vi, create a data file called “.addr_book” in your home directory. This file is a book of contacts and should contain entries for people, businesses, etc.

Note that each entry is a single line! Have at least 3 entries in the file. (Don’t have any blank lines or any comment lines.) Here is another example using generic information: Firstname Lastname – jobtitle – email: lastname.firstname@emailserver.com

2. Start a session log with the script command for your command line work. You can type exit before using interactive utilities, like vi, but remember to restart your session log when you leave vi.

3. Use utilities to search for entries in your .addr_book file and display them. For example, one command could lookup my entry and display it, then another command could lookup your entry and display it.

4. If you don’t already have one, create a “bin” directory within your home directory

5. Create an empty file in your bin directory called “lookup” and make it executable with appropriate permissions (so you can view or modify or execute your script).

6. Using vi, edit the file called “lookup” that you created in step 6. You will use positional parameters in this script. The script should perform the following tasks:
– Display a message such as “Searching for” then display the positional parameter(s) provided when the script is executed.
– Using positional parameters, find the entry in the “$HOME/.addr_book” file that matches the positional parameter(s) provided when the script is executed.
-Then, display a message such as “All Address Book Entries: ”
-Display all lines from the file in sorted order. The output MUST be sorted. You can sort the entire line, you are not required to sort on any specific part of the line. However, if you would like an extra challenge, try sorting on the last name.

The output of the lookup script might look something like this when the positional parameter “Doe” is used when the script executes (two entries in the file are shown in this example):

While recording to your session log, run your script at the command line. I do not recommend running the session log while you are in vi.

(HINT: use grep and sort)

Last Updated on February 10, 2019 by EssayPro