SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 31st, 2004, 08:12 PM
Hidden_Secrets Hidden_Secrets is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 Hidden_Secrets User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHONE BOOK ENTRIES help.

this is the script that i have for the phone book entry:
*****************************************
****************************************
if [ "$#" -ne 0 ]
then
lu "$@"
exit
fi
validchoice=""
until [ -n "$validchoice" ]
do


echo "s - search for an entry"
echo "a - add an entry"
echo "u - update phone directory"
echo "r - remove an entry"
echo "x - exit"


read choice
case "$choice"

in


s) echo "Enter name to look up: \c"
read name
grep "$name" /home/ce435a14/assign2/phonedir;
echo $fnamelname ":" $businessnumber ":" $homenumber ":" $comments
validchoice=TRUE;;


a) echo "Enter first and last name: \c"
read fnamelname
echo "Enter business phone number: \c"
read businessnumber
echo "Enter home phone numer: \c"
read homenumber
echo "Enter description: \c"
read comments
echo $fnamelname ":"$businessnumber " (h) :" $homenumber "(o) :" $comments >> /home/ce435a14/assign2/phonedir
echo "Done !"
validchoice=TRUE;;


u) vi /home/ce435a14/assign2/phonedir ;;


r) echo "Enter name to be removed: \c"
read name
grep -v "$name" phonedir > /tmp/phonedir;
mv /tmp/phonedir phonedir;
validchoice=TRUE;;


x) echo "Goobye. \c"
echo ""
validchoice=TRUE;;


*) echo "You have entered an invalid option, please eneter a valid option [s,a,u,x]" ;;
esac
done
********************************************************************************************

this scrpt can add entries, update entries, search for entries and also quits properly.

Need assistance on :

- when searching for names display only the name, phones and comments,
-delete entries from the phoenbook but using the command "SED" i used the command grep to delete entry it works but i dontknow how to use "SED"
-add changes to create "phonedir" file, if it doesnt exist
-add a label entry to the phone menu (I|L) that will search for a pattern in the phone directory and displa the name and address in the label format:
for ex. for the user JOHN it shud show :
John Jones
5 Front Street
Ottawa, Ontario
K2S 2S4
-finally, performn multiple actions under the same option of selected menu. exit selected option to go back to a main menu whenuser enters an empty string or ^C (CTL+C) or ^D (ctrl+D). display # of searces or additions or deletions that were performed.

can someone please help me with these questions.. i hope someone can.. i really need you help..please can you take a lil bit of ur time and help me.. thankyou so much..

Reply With Quote
  #2  
Old August 1st, 2004, 10:32 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
more then assistance, you need a good shell book.
i will give you an exemple (last time in my life, i am tired to do this)
Code:
#!/bin/sh

# i sure will use an other (not sh) tool to do this !

[ $# -ne 0 ] && exit 1

BOOK=/home/ce435a14/assign2/phonedir

menu()
{
# i love 'sort'
   echo "a - add an entry"
   echo "r - remove an entry"
   echo "s - search for an entry"
   echo "u - update phone directory"
   echo
   echo "q - quit" # this entry does not matter
   read ans; case $ans in [saur]*) return 0;; esac
   return 1;
}
check4name()
{
    [ x$1 = x ] && return 1 # nothing entered
    case `grep -c $1 $BOOK >/dev/null` in 1) return 0;; esac
    return 1 # not found or not unique
}

# twice grep is cheaper as storing output

while .
do menu || break
case $ans in s*)
     printf "Enter name to look up: "
     read name; check4name $name || continue
     grep $name $BOOK
     break
;; u*)
     vi $BOOK ; break
;; r*)
     printf "Enter name to be removed: "
     read name; check4name $name || continue
     grep -v $name $BOOK > $HOME/tmp.book
# or using sed
# sed -e "/$name/d" $BOOK > $HOME/tmp.book
# NEVER use /tmp, nobody says you can write /tmp/filename
# maybe is still there, owned by somebody else :(
# the only place you sure can (over)write is: $HOME
     mv $HOME/tmp.book $BOOK
     break
######  and more code
;; esac
done
echo Goobye.
exit 0



# nota
# the ending exit is in sh not needed (default is 0), anyway always
# give an exit status to your codes, this will help you later
# spaces in most of progs are IGNORED, so use it to make your
# code readable by humans, not for machine
# THE notation:
Code:
#    case x in a) ksjdhfkjkfsfhks;;
#    b) aaa;;
#    c) asjfhksajdfa; dsgjfdkjglajk; dskjlglkjfdl;;
#    *) exit;; esac
# AND 
#    case x in a) ksjdhfkjkfsfhks
#    ;;        b) aaa
#    ;;        c) asjfhksajdfa
#                 dsgjfdkjglajk
#                 dskjlglkjfdl
#    ;;        *) exit
#    ;; esac

#
# are absolutely the SAME, which can YOU better read ?
# columning is very easy + efficient way to SEE errors

# i inserted the same ERROR in this 2 case
# in first one, you need to read the code
# in second, it's simply flamboyant

Code:
#    case x in a) ksjdhfkjkfsfhks;;
#    b) aaa;
#    c) asjfhksajdfa; dsgjfdkjglajk; dskjlglkjfdl;;
#    *) exit;; esac


# ---- first try to get it out, then scroll to see below
























Code:

#    case x in a) ksjdhfkjkfsfhks
#    ;;        b) aaa
#    ;         c) asjfhksajdfa
#                 dsgjfdkjglajk
#                 dskjlglkjfdl
#    ;;        *) exit
#    ;; esac

Last edited by guggach : August 1st, 2004 at 10:35 AM. Reason: typo

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > PHONE BOOK ENTRIES help.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway