if [ ! -f dbms ]
then
touch dbms
fi
while [ 1 ]
do
echo " "
echo " "
echo " "
echo " The database management system operations : "
echo " 1.For inserting data into the file "
echo " 2.View all record of file "
echo " 3.For searching the data from the file "
echo " 4.For sorting the data of file "
echo " 5.For modifying the data into the file "
echo " 6.For Delete the record "
echo " 7.For Exit "
echo " Enter your choice : "
read choice
clear
case $choice in
1)echo " Enter the data you want to enter in the file "
echo " Enter the roll no "
read rno
echo " Enter the name "
read name
echo " Enter the branch "
read branch
similar=`grep -c "$rno" dbms`
if [ $similar -eq 1 ]
then
echo " The entered roll no. violates the primary key constraint on roll no "
else
echo " $rno|$name|$branch " | cat >> dbms
echo " The data has been added "
fi
;;
2)echo " The content of file is:"
cat dbms
;;
3)echo " Enter the word you want to search from the file "
read word
search=` grep -c -i "$word" dbms `
if [ $search -eq 0 ]
then
echo " no such roll no. exist in the file "
else
grep -i "$word" dbms
fi
;;
4)echo " Enter the technic by which you want to sort "
echo " 1.Sort by rno. "
echo " 2.Sort by name "
echo " 3.Sort by branch "
read choice
sort -t "|" -k $choice dbms
;;
5)echo " Enter The Roll No which wii be modified : "
read rno
search=` grep -c -i "$word" dbms `
if [ $search -eq 0 ]
then
echo " no such roll no. exist in the file "
else
grep -v "$rno" dbms > temp
mv temp dbms
echo " Enter the roll no "
read rno
echo " Enter the name "
read name
echo " Enter the branch "
read branch
similar=`grep -c "$rno" dbms`
if [ $similar -eq 1 ]
then
echo " The entered roll no. violates the primary key constraint on roll no "
else
echo " $rno|$name|$branch " | cat >> dbms
echo " The data has been modified "
fi
fi
;;
6)echo " Enter The Roll No which wii be deleted : "
read rno
search=` grep -c -i "$word" dbms `
if [ $search -eq 0 ]
then
echo " no such roll no. exist in the file "
else
grep -v "$rno" dbms > temp
mv temp dbms
echo " The data has been deleted "
fi
;;
7)exit;
;;
*)echo " Invalid entry"
;;
esac
done