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 September 5th, 2004, 03:43 AM
greengoblin69 greengoblin69 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 greengoblin69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Unix Scripting for a simple menu

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

Reply With Quote
  #2  
Old September 5th, 2004, 06:54 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 49 m 57 sec
Reputation Power: 9
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Unix Scripting for a simple menu


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 4 hosted by Hostway