|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
I am trying to create a small menu that prints, searchs for specific records, adds, and deletes records. I am a newbie so this might look really bad .These records are in one file called records seperated by ":". These contain first name ,surname, telephone no. etc.
here is some of my code record_file=records add_file=add delete_file=delete testfile = record_file if testfile ! -f $ /home/alacritas/students/jdacosta/kxa254***1/pract/record_file ; then echo "File 'record_file' Not Found" exit fi testfile = add_file if tesfile ! -f /home/alacritas/students/jdacosta/kxa254***1/pract/add_file ; then echo "File 'add_file' Not Found" exit fi testfile = delete_file if testfile ! -f /home/alacritas/students/jdacosta/kxa254***1/pract/delete_file ; then echo "File 'delete_record' Not Found" exit fi while [ varname! = q ] do echo "************************" echo " Employee Info Main Menu " echo "************************" echo " " echo " 1 - Print all Current Records" echo " 2 - Print all Current Records (formatted)" echo " 3 - Print Names and Phone Numbers" echo " 4 - Print Names and Phone Numbers (formatted)" echo " 5 - Search for specific Record(s)" echo " 6 - Add new Records" echo " 7 - Delete Records" echo " " echo " q - Quit" echo " " echo " Please enter your selection"/c read varname case $varname in [ 1 ]) echo " Your Selection: 'varname'" cat $record_file | awk -F":"'{print $1,$2,$3,$4,$5,$6,$7}' echo " Press Enter to Continue "/c read dummy;; [ 2 ]) echo " Your Selection: 'varname'" cat $record_file | awk -F":"'{printf "%-10s %-10s %-2s %-12s %-3s %-15 %-10", $2,$3,$4,$1,$5,$6,$7}' echo " Press Enter to Continue "/c read dummy;; [ 3 ]) echo " Your Selection: 'varname'" cat $record_file | awk -F":"'{print $2,$3,$1}' echo " Press Enter to Continue "/c read dummy;; [ 4 ]) echo " Your Selection: 'varname'" cat $record_file | awk -F":"'{printf "%-10s %-10s %-10s", $2,$3,$1}' echo " Press Enter to Continue "/c read dummy;; [ 5 ])echo " Your Selection: 'varname'" echo " Enter Keyword: 'keyword'" cat $record_file | grep -i [ 6 ])$add_file;; [ 7 ])$delete_file;; [Q q ]) break;; *) echo "Bad Option" "") echo "Please choose Valid Option" esac done Can somebody please help me with using grep and sed. Any alterrations will be much appriciated for number 5 : the user inputs the surname of the staff and the whole record is printed out. Please help |
|
#2
|
|||
|
|||
|
say, you need butter, bread and wine
how many times you go to store ? what's that 'kxa254***1' and 'if testfile ! -f $ /home/alacri....' and what's 'testfile' and: 'testfile = add_file' realize: i don't remember how the shell inperpretes: [ 5 ]) note the spaces and brakets, i would write 5) -------------- [ 5 ])echo " Your Selection: 'varname'" echo " Enter Keyword: 'keyword'" cat $record_file | grep -i ## this statement has NO ending ';;' make nothing, is hanging because 'grep' does not know what to do! [Q q ]) break;; #i write this: [qQ]) *) echo "Bad Option" "") echo "Please choose Valid Option" #this statement has NO chance to be reached, a) missing ending ';;' b) '*' has an higher priority ... also note: 'cat xxx|grep abc' AND 'grep abc xxx' IS THE SAME, but unix. you need a book! Last edited by guggach : September 5th, 2004 at 06:57 AM. Reason: typo |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Unix Scripting for a simple menu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|