Shell Scripting n00b

Hey Guys!

I was hoping for some help with a simple script I'm trying to use. I have the script set up to pull some simple information out of a database .txt file and sed it into a preexisting template for assignment cover letters. The problem seems to be someplace in the sed statement but I can't find it. Any insights? Code attached. TIA!

No idea. But here's the script for somebody that might me able to help.
(For future reference it's probably better to use the '#' in the toolbar to surrounding your code ;-).

#!/bin/bash
echo
echo "Your name please."
read STUDENT
echo
echo "Your student ID number please"
read STUDID
echo
echo "Enter submission title please."
read TITLE
echo
echo "Enter submission subtitle please."
read SUBTITLE
echo
echo "Pick course number"
echo
echo "HDWR1000 | PROG1040 | OSYS1000 | SAAD2000"
echo "      DBAS2020 | ICOM1325 | ICOM1200"
read CLASSNUM
echo
echo "Preferred file name?"
read FILENAME
TIM=`date`

	if [ $CLASSNUM=HDWR1000 ]; then
	CLASS=`awk -F":" 'NR==2 {print $1}' < dbase.txt`
		TEACHER=`awk -F":" 'NR==2 {print $2}' < dbase.txt`
		SECTION=`awk -F":" 'NR==2 {print $5}' < dbase.txt`
	elif [ $CLASSNUM=PROG1040 ]; then
	CLASS=`awk -F":" 'NR==3 {print $1}' < dbase.txt`
		TEACHER=`awk -F":" 'NR==3 {print $2}' < dbase.txt`
		SECTION=`awk -F":" 'NR==3 {print $5}' < dbase.txt`
	elif [ $CLASSNUM=OSYS1000 ]; then
	CLASS=`awk -F":" 'NR==5 {print $1}' < dbase.txt`
		TEACHER=`awk -F":" 'NR==5 {print $2}' < dbase.txt`
		SECTION=`awk -F":" 'NR==5 {print $5}' < dbase.txt`
	elif [ $CLASSNUM=SAAD2000 ]; then
	CLASS=`awk -F":" 'NR==4 {print $1}' < dbase.txt`
		TEACHER=`awk -F":" 'NR==4 {print $2}' < dbase.txt`
		SECTION=`awk -F":" 'NR==4 {print $5}' < dbase.txt`
	elif [ $ClassNum=DBAS2020 ]; then
	CLASS=`awk -F":" 'NR==1 {print $1}' < dbase.txt`
		TEACHER=`awk -F":" 'NR==1 {print $2}' < dbase.txt`
		SECTION=`awk -F":" 'NR==1 {print $5}' < dbase.txt`
	elif [ $CLASSNUM=ICOM1325 ]; then
	CLASS=`awk -F":" 'NR==6 {print $1}' < dbase.txt`
		TEACHER=`awk -F":" 'NR==6 {print $2}' < dbase.txt`
		SECTION=`awk -F":" 'NR==6 {print $5}' < dbase.txt`
	elif [ $CLASS=ICOM1200 ]; then
	CLASS=`awk -F":" 'NR==7 {print $1}' < dbase.txt`
		TEACHER=`awk -F":" 'NR==7 {print $2}' < dbase.txt`
		SECTION=`awk -F":" 'NR==7 {print $5}' < dbase.txt`
	else echo "Please restart script."
fi

sed "s/DATETIME/$TIM/" <template.txt >$FILENAME.txt
sed "s/SUBTITLE/$SUBTITLE/" $FILENAME.txt
sed "s/CLASS/$CLASS/" $FILENAME.txt
sed "s/STUDENT/$STUDENT/" $FILENAME.txt
sed "s/STUDID/$STUDID/" $FILENAME.txt
sed "s/TITLE/$TITLE/" $FILENAME.txt
sed "s/SECTION/$SECTION/" $FILENAME.txt  
sed "s/TEACHER/$TEACHER/" $FILENAME.txt


echo
echo "Thank you! Your cover page $FILENAME.txt has been created."
echo

what error are you getting when trying to execute?

could you post the contents or structure of your dbase.txt : there are many things to optimize in your script, mainly the long if then elif .... wich could be made with a simple loop.

DBAS2020:Brian Shewan:Brad Feicht:W0203027:702:
HDWR1000:Todd Verge:Brad Feicht:W0203027:702:
PROG1040:Karen Gillespie:Brad Feicht:W0203027:702:
SAAD2000:David Russell:Brad Feicht:W0203027:702:
OSYS1000:Hal O'Connell:Brad Feicht:W0203027:702:
ICOM1325:Hal O'Connell:Brad Feicht:W0203027:702:
ICOM1200:Scott Lessel:Brad Feicht:W0203027:702:

That would be the database and the error I'm getting tells me that theres an error in expression #6 and character 13. I moved expression #6 to the front of the sed then reformatted the script and have it as you see. The sed statement was using -e to sed all variables into the template.

I hope that helps.
Brad

the problem comes probably from the date string, what gives the date command on your os ?

#! /bin/bash
# Reads the contents of the file and put it in arrays
i=0
OLDIFS=$IFS; IFS=":"
while read C T D E S
do
	((i++))
	CLASS[$i]=$C
	TEACHER[$i]=$T
	SECTION[$i]=$S
done < dbase.txt
IFS=$OLDIFS
echo
read -p "Your name please " STUDENT
echo
read -p "Your student ID number please " STUDID
echo
read -p "Enter submission title please " TITLE
echo
read -p "Enter submission subtitle please " SUBTITLE
echo
for ((i=1; i<${#CLASS[@]}; i++))
do	echo "$i) ${CLASS[$i]}"
done
read -p "Pick course number " i
echo
read -p "Preferred file name? " FILENAME
echo
if sed -e "s/DATETIME/$(date)/" -e "s/SUBTITLE/$SUBTITLE/" -e "s/CLASS/${CLASS[$i]}/" -e "s/STUDENT/$STUDENT/" -e "s/STUDID/$STUDID/" -e "s/TITLE/$TITLE/" -e "s/SECTION/${SECTION[$i]}/" -e "s/TEACHER/${TEACHER[$i]}/" template.txt > $FILENAME.txt
then
	echo "Thank you! Your cover page $FILENAME.txt has been created."
	cat $FILENAME.txt
else
	echo "An error occured"
fi