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