printf "Enter a File Name : "
read fname
while [ 1 ]
do
echo " "
echo " ***** MENU **** "
echo "1) Create Record"
echo "2) View Record"
echo "3) Insert Record"
echo "4) Delete Record"
echo "5) Search"
echo "6) Exit"
echo "Enter your choice : "
read ch
case "$ch" in
1)
echo "CREATE"
echo "Enter student info : \n"
echo "Roll No. : "
read rno
echo "Name : "
read name
echo "Year : "
read year
echo "Branch : "
read branch
echo "Percentage : "
read per
printf "%d\t%s\t%s\t%s\t%s\n" $rno $name $year $branch $per >> $fname
;;
2)
echo "VIEW"
if [ -e $fname ]
then
cat $fname
else
echo "File does not exist"
fi
;;
3)
echo "INSERT"
echo "Enter student info : \n"
echo "Roll No. : "
read rno
echo "Name : "
read name
echo "Year : "
read year
echo "Branch : "
read branch
echo "Percentage : "
read per
printf "%d\t%s\t%d\t%d\t%d" $rno $name $year $branch $per >> $fname
;;
4)
echo "DELETE"
echo "Enter roll no which u want to delete : "
read rno
grep "$rno" "$fname"
ans=$?
if [ $ans -eq 0 ]
then
echo "Record Found"
grep -v "$rno" "$fname"
rm "$fname"
mv temp.dat "$fname"
echo "Record deleted !!!"
else
echo "Record not found"
fi
;;
5)
echo "SEARCH"
echo " "
echo "Result of a particular record"
echo "Enter roll no which u want to search: "
read rno
grep "$rno" "$fname"
ans=$?
if [ $ans -eq 0 ]
then
echo "Record Found"
else
echo "Record not found"
fi
;;
6)
exit
;;
*)
echo "Invalid choice"
esac
done
read fname
while [ 1 ]
do
echo " "
echo " ***** MENU **** "
echo "1) Create Record"
echo "2) View Record"
echo "3) Insert Record"
echo "4) Delete Record"
echo "5) Search"
echo "6) Exit"
echo "Enter your choice : "
read ch
case "$ch" in
1)
echo "CREATE"
echo "Enter student info : \n"
echo "Roll No. : "
read rno
echo "Name : "
read name
echo "Year : "
read year
echo "Branch : "
read branch
echo "Percentage : "
read per
printf "%d\t%s\t%s\t%s\t%s\n" $rno $name $year $branch $per >> $fname
;;
2)
echo "VIEW"
if [ -e $fname ]
then
cat $fname
else
echo "File does not exist"
fi
;;
3)
echo "INSERT"
echo "Enter student info : \n"
echo "Roll No. : "
read rno
echo "Name : "
read name
echo "Year : "
read year
echo "Branch : "
read branch
echo "Percentage : "
read per
printf "%d\t%s\t%d\t%d\t%d" $rno $name $year $branch $per >> $fname
;;
4)
echo "DELETE"
echo "Enter roll no which u want to delete : "
read rno
grep "$rno" "$fname"
ans=$?
if [ $ans -eq 0 ]
then
echo "Record Found"
grep -v "$rno" "$fname"
rm "$fname"
mv temp.dat "$fname"
echo "Record deleted !!!"
else
echo "Record not found"
fi
;;
5)
echo "SEARCH"
echo " "
echo "Result of a particular record"
echo "Enter roll no which u want to search: "
read rno
grep "$rno" "$fname"
ans=$?
if [ $ans -eq 0 ]
then
echo "Record Found"
else
echo "Record not found"
fi
;;
6)
exit
;;
*)
echo "Invalid choice"
esac
done
No comments:
Post a Comment