#Assignment 2 : B.
Write a program to implement an address book with options given below: a)
#Create address book. b) View address book. c) Insert a record. d) Delete a record. e) Modify a
#record. f) Exit
[Link]
#-------------------------------------------------------------------------------------------------------------------
#!bin/bash
echo -e "\n\t\tWelcome to our Address Book !\n"
while true
do
echo -e "Select your option : \[Link] data \[Link] data\[Link] using name\
[Link] using name \[Link] using name\[Link]\n\t\t"
read ch
case $ch in
1)
while true
do
echo -e "\nEnter the record : "
echo "Eno. : "
read eno
echo "Ename : "
read ename
while true
do
echo "Mob no. : "
read mno
len=${#mno}
if test $len = 10
then
break
else
echo -e "\n\t\tInvalid number please enter again ! "
fi
done
echo "City : "
read city
echo -e "$eno\t$ename\t$mno\t$city" >> [Link]
echo -e "\n\nDo you want to enter more records ? [y/n] : "
read cho
if test $cho = n
then
break
fi
done
echo -e "\n\t\t Records added succesfully !\n"
;;
2) if [[ -s [Link] ]]
then
echo -e "\n\n---------Records---------\n"
cat [Link]
echo -e "\n\n"
else
echo -e "\n\t\tFile is empty !\n"
fi
;;
3)
echo -e "\nEnter the name to be searched : "
read s_name
echo
grep -i $s_name [Link]
echo
;;
4)
echo -e "\nEnter the name to be deleted : "
read d_name
#grep -v $d_name [Link] > temp
#mv temp [Link]
sed -i "/$d_name/d" [Link]
echo -e "\n\t\t Record deleted succesfully !\n"
;;
5)
echo -e "\nEnter the name for record to be modified : "
read m_name
no=`grep -n $m_name [Link] | cut -c 1`
echo -e "\nEnter the value that you want to modify :"
read m_value
echo -e "\nEnter the new value : "
read n_value
sed -i "$no s/$m_value/$n_value/" [Link]
echo -e "\n\t\t Record modified successfully !"
;;
*)
echo -e "\nProgram Finished due to exit or wrong option !"
break 2
;;
esac
done
rm [Link]
#Output:
samarth@samarth-OptiPlex-7010:~$ chmod 777 [Link]
samarth@samarth-OptiPlex-7010:~$ bash [Link]
Welcome to our Address Book !
Select your option :
[Link] data
[Link] data
[Link] using name
[Link] using name
[Link] using name
[Link]
1
Enter the record :
Eno. :
1
Ename :
aaa
Mob no. :
9898989898
City :
pune
Do you want to enter more records ? [y/n] :
y
Enter the record :
Eno. :
2
Ename :
bbb
Mob no. :
9090909090
City :
nagar
Do you want to enter more records ? [y/n] :
y
Enter the record :
Eno. :
3
Ename :
ccc
Mob no. :
9000000000
City :
nashik
Do you want to enter more records ? [y/n] :
n
Records added succesfully !
Select your option :
[Link] data
[Link] data
[Link] using name
[Link] using name
[Link] using name
[Link]
2
---------Records---------
1 aaa 9898989898 pune
2 bbb 9090909090 nagar
3 ccc 9000000000 nashik
Select your option :
[Link] data
[Link] data
[Link] using name
[Link] using name
[Link] using name
[Link]
Enter the name to be searched :
bbb
2 bbb 9090909090 nagar
Select your option :
[Link] data
[Link] data
[Link] using name
[Link] using name
[Link] using name
[Link]
Enter the name to be deleted :
bbb
Record deleted succesfully !
Select your option :
[Link] data
[Link] data
[Link] using name
[Link] using name
[Link] using name
[Link]
---------Records---------
1 aaa 9898989898 pune
3 ccc 9000000000 nashik
Select your option :
[Link] data
[Link] data
[Link] using name
[Link] using name
[Link] using name
[Link]
Enter the name for record to be modified :
ccc
Enter the value that you want to modify :
ccc
Enter the new value :
ddd
Record modified successfully !
Select your option :
[Link] data
[Link] data
[Link] using name
[Link] using name
[Link] using name
[Link]
---------Records---------
1 aaa 9898989898 pune
3 ddd 9000000000 nashik
Select your option :
[Link] data
[Link] data
[Link] using name
[Link] using name
[Link] using name
[Link]
Program Finished due to exit or wrong option !
samarth@samarth-OptiPlex-7010:~$