If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Menu System

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-21-03, 13:07
htaha htaha is offline
Registered User
 
Join Date: Oct 2003
Location: IL. USA
Posts: 7
Question Menu System

I wrote a menu system where a user can select from the menu and do different things, but there are a couple functions that I am having a problem with. I have a text file with 5 fields seperated by a # delimiter.
First, How can I delete one line out of this text file which is called TS_DATA? Second, The last field on every line consist of the hours worked, How can I add those hours and display the total, also how can I do this by user name which is the second field in the file or by project name for all users which is the third field? Third, I have two other text files, one contains the project names PROJ_LIST, the other contains the task names TASK_LIST, how can I delete for example a project name out the file? And a task name out of the other file? If you look at my script below, I am having problems with options 5, 7, 8? Any ideas?

Here is sample of TS_DATA file
2003/10/14#htaha#12Unix#Testing#2
2003/10/13#Husam#15Unix#Administration#5
2003/10/14#test#14Shell#Coding#4
2003/10/14#mike#15Unix#Testing#4
2003/10/20#htaha#12Unix#Production#3
2003/10/20#htaha#13OrderEntry#Development#8

Here is a sample of PROJ_LIST file
12Unix
13OrderEntry
14FinanceSystem
15CreditSystem
16HRSystem
17Marketing
18Merchandising

Here is my script:
# Initialize Variables
FLAG_UR=0
FLAG_PR=0
FLAG_AP=0
FLAG_DP=0
FLAG_AT=0
FLAG_DT=0


while true
do
cat <<MENU

* * * * MAIN MENU * * * *

1) Sort Report by Date
2) Sort Report by User Name
3) Sort Report by Project Name
4) Add a new Project
5) Delete an existing Project
6) Add a new Task
7) Delete an existing Task
8) Total hours for all projects combined

x) exit

\?) echo "Bad Choice"


Pick your choice:

MENU

read CHOICE

case $CHOICE
in
1) FLAG_UR=1
echo "Report will be sorted by Date "
echo "Sorted user report will be saved in a file called SORTED_DR "
sort -o SORTED_DR TS_DATA
cat SORTED_DR ;;

2) FLAG_UR=1
echo "Report will be sorted by User Name "
echo "Sorted user report will be saved in a file called SORTED_UR "
sort -o SORTED_UR TS_DATA
cat SORTED_UR ;;

3) FLAG_PR=1
echo "Report will be sorted by Project Name "
sort -k 3,3 TS_DATA
cat TS_DATA ;;
# cut -d# -f3 TS_DATA >PROJ_NAME
# sort -o S_PROJ_NAME PROJ_NAME
# cat S_PROJ_NAME ;;
# sort -o PROJLIST S_PROJ_NAME
# cut -d# -f4 TS_DATA > TASK_NAME
# sort -o S_TASK_NAME TASK_NAME
# cat S_TASK_NAME
# sort -o TASKLIST S_TASK_NAME ;;

4) FLAG_AP=1
echo "Enter a new Project to be added (Project Name should begin with a two digit number): \c"
read PROJ
grep -i "^$PROJ" S_PROJ_NAME
if [[ $? -eq 0 ]]
then
echo "Project: $PROJ already exists, Please review your entry again "
else
echo $PROJ >> S_PROJ_NAME
sort -o PROJLIST S_PROJ_NAME
fi ;;

5) FLAG_DP=1
echo "***Project List***\n`cat PROJ_LIST`\n"
echo "Select an existing Project to be Removed: "
read PROJ
if [ -z "$PROJ" ]
then
echo "Removal ignored"
else
cut -c1-15 PROJ_LIST >test1
fi ;;

6) FLAG_AT=1
echo "Enter a New Task to be added: \c"
read TASK
grep "^$TASK" S_TASK_NAME
if [[ $? -eq 0 ]]
then
echo "Task: $TASK already exists, Please review your entry again "
else
echo $TASK >> S_TASK_NAME
sort -o TASKLIST S_TASK_NAME
fi ;;

7) Flag_DT=1
echo "Select an existing Task to be Removed: "
select TASK in `cat $TASKLIST`
do
break
done
grep -v "^$TASK$" $TASKLIST >> TASKLIST ;;

x) exit ;;

*) echo "$CHOICE is a bad choice, try again " ;;

esac
done

Last edited by htaha; 10-21-03 at 19:14.
Reply With Quote
  #2 (permalink)  
Old 10-21-03, 23:33
heavenson heavenson is offline
Registered User
 
Join Date: Oct 2003
Posts: 1
Cool Re: Menu System

To delete the projects or task,
simply do :

cat PROJECT_LIST | grep -v $project > PROJECT_LIST.tmp
mv PROJECT_LIST.tmp PROJECT_LIST

should be same for delete task


to count the total

do
for line in `cat TS_DATA file`
do

mynum=`echo $line | awk -F# 'print {$5}`
total=expr total + mynum

done


Quote:
Originally posted by htaha
I wrote a menu system where a user can select from the menu and do different things, but there are a couple functions that I am having a problem with. I have a text file with 5 fields seperated by a # delimiter.
First, How can I delete one line out of this text file which is called TS_DATA? Second, The last field on every line consist of the hours worked, How can I add those hours and display the total, also how can I do this by user name which is the second field in the file or by project name for all users which is the third field? Third, I have two other text files, one contains the project names PROJ_LIST, the other contains the task names TASK_LIST, how can I delete for example a project name out the file? And a task name out of the other file? If you look at my script below, I am having problems with options 5, 7, 8? Any ideas?

Here is sample of TS_DATA file
2003/10/14#htaha#12Unix#Testing#2
2003/10/13#Husam#15Unix#Administration#5
2003/10/14#test#14Shell#Coding#4
2003/10/14#mike#15Unix#Testing#4
2003/10/20#htaha#12Unix#Production#3
2003/10/20#htaha#13OrderEntry#Development#8

Here is a sample of PROJ_LIST file
12Unix
13OrderEntry
14FinanceSystem
15CreditSystem
16HRSystem
17Marketing
18Merchandising

Here is my script:
# Initialize Variables
FLAG_UR=0
FLAG_PR=0
FLAG_AP=0
FLAG_DP=0
FLAG_AT=0
FLAG_DT=0


while true
do
cat <<MENU

* * * * MAIN MENU * * * *

1) Sort Report by Date
2) Sort Report by User Name
3) Sort Report by Project Name
4) Add a new Project
5) Delete an existing Project
6) Add a new Task
7) Delete an existing Task
8) Total hours for all projects combined

x) exit

\?) echo "Bad Choice"


Pick your choice:

MENU

read CHOICE

case $CHOICE
in
1) FLAG_UR=1
echo "Report will be sorted by Date "
echo "Sorted user report will be saved in a file called SORTED_DR "
sort -o SORTED_DR TS_DATA
cat SORTED_DR ;;

2) FLAG_UR=1
echo "Report will be sorted by User Name "
echo "Sorted user report will be saved in a file called SORTED_UR "
sort -o SORTED_UR TS_DATA
cat SORTED_UR ;;

3) FLAG_PR=1
echo "Report will be sorted by Project Name "
sort -k 3,3 TS_DATA
cat TS_DATA ;;
# cut -d# -f3 TS_DATA >PROJ_NAME
# sort -o S_PROJ_NAME PROJ_NAME
# cat S_PROJ_NAME ;;
# sort -o PROJLIST S_PROJ_NAME
# cut -d# -f4 TS_DATA > TASK_NAME
# sort -o S_TASK_NAME TASK_NAME
# cat S_TASK_NAME
# sort -o TASKLIST S_TASK_NAME ;;

4) FLAG_AP=1
echo "Enter a new Project to be added (Project Name should begin with a two digit number): \c"
read PROJ
grep -i "^$PROJ" S_PROJ_NAME
if [[ $? -eq 0 ]]
then
echo "Project: $PROJ already exists, Please review your entry again "
else
echo $PROJ >> S_PROJ_NAME
sort -o PROJLIST S_PROJ_NAME
fi ;;

5) FLAG_DP=1
echo "***Project List***\n`cat PROJ_LIST`\n"
echo "Select an existing Project to be Removed: "
read PROJ
if [ -z "$PROJ" ]
then
echo "Removal ignored"
else
cut -c1-15 PROJ_LIST >test1
fi ;;

6) FLAG_AT=1
echo "Enter a New Task to be added: \c"
read TASK
grep "^$TASK" S_TASK_NAME
if [[ $? -eq 0 ]]
then
echo "Task: $TASK already exists, Please review your entry again "
else
echo $TASK >> S_TASK_NAME
sort -o TASKLIST S_TASK_NAME
fi ;;

7) Flag_DT=1
echo "Select an existing Task to be Removed: "
select TASK in `cat $TASKLIST`
do
break
done
grep -v "^$TASK$" $TASKLIST >> TASKLIST ;;

x) exit ;;

*) echo "$CHOICE is a bad choice, try again " ;;

esac
done
Reply With Quote
  #3 (permalink)  
Old 10-22-03, 12:36
htaha htaha is offline
Registered User
 
Join Date: Oct 2003
Location: IL. USA
Posts: 7
Re: Menu System

Thank you heavenson,
I believe this is exactly what I was looking for.

I will try it and let you know.

Quote:
Originally posted by heavenson

To delete the projects or task,
simply do :

cat PROJECT_LIST | grep -v $project > PROJECT_LIST.tmp
mv PROJECT_LIST.tmp PROJECT_LIST

should be same for delete task


to count the total

do
for line in `cat TS_DATA file`
do

mynum=`echo $line | awk -F# 'print {$5}`
total=expr total + mynum

done
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On