Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a bash shell script, named look for that prints the lines in a phone-book

ID: 3852752 • Letter: W

Question

Write a bash shell script, named look for that prints the lines in a phone-book that contain the name of the person(s) passed to the script as input parameter(s). The phonebook is stored in a file named contacts, where each entry is formatted as in the following examples: 04 5990 8768 Bob 08 8337 2443 Takeo 03 5588 8798 Bruce ..etc. Your script must be able to search the phonebook for more than one name, and must not care whether the name is typed in upper- or lowercase letters. For example, the output from the command: look for Bruce Billy Bob Would be: 03 5588 8798 Bruce 04 5990 8768 Bob

Explanation / Answer

#!/bin/bash

if [ $# -lt 1 ]; then
echo $0: usage: ./lookfor name to search in contact.txt
exit 1
fi

while [ $# -gt 0 ]
do
echo | grep $1 contact.txt
shift
done   

--------------------------------------------------------------------------------------------------------------------------------------------------------------

//output

./lookfor Bruce Bob billy                                                                                                                                               

03 5588 8798 Bruce                                                                                                                                                              

04 5990 8768 Bo

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote