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 BobExplanation / 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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.