0% found this document useful (0 votes)
14 views6 pages

NAME-Sathe Pratidnya Te-B ROLL NO-T512046

This document is a Bash script that provides a menu-driven interface for managing a database. Users can create a database, add records, display records, search for records, delete records, modify records, or exit the program. The script includes input validation and uses basic file operations to manipulate the database files.

Uploaded by

pratidnyasathe07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

NAME-Sathe Pratidnya Te-B ROLL NO-T512046

This document is a Bash script that provides a menu-driven interface for managing a database. Users can create a database, add records, display records, search for records, delete records, modify records, or exit the program. The script includes input validation and uses basic file operations to manipulate the database files.

Uploaded by

pratidnyasathe07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NAME-Sathe Pratidnya TE-B ROLL NO-T512046

#!/bin/bash

it=0

a=1

while [[ $op -lt 7 ]]

do

echo "Enter the options"

echo "1 for create"

echo "2 for add"

echo "3 for display"

echo "4 for search"

echo "5 for delete"

echo "6 for modify"

echo "7 for exit"

echo "enter your choice"

read op

word="$op"

case "$word" in

"1")

if [ "$op" == "1" ]

then

echo "Enter name for db"

read db

touch "$db"

fi;;

"2")

if [ "$op" == "2" ]

then

echo "Which db u want to add"


read db

echo "Enter number of records"

read n

while [ $it -lt $n ]

do

echo "Enter id"

read id1

echo "Enter name"

read nm

pa1="^[A-Z a-z]"

echo "Enter phone number"

read ph

pat="^[0-9]{10}"

it=$(expr $it + 1)

echo "$id1 $nm $ph" >> "$db"

done

echo "$it Record entered"

fi;;

"3")

if [ "$op" == "3" ]

then

echo "Enter name for db from where u want to read"

read db

cat $db

fi;;

"4")

if [ "$op" == "4" ]

then

echo "Enter name of db where u want to search"


read db

echo "enter ph"

read ph

if grep "$ph" "$db"; then

echo "record found"

else

echo "not found"

fi

fi;;

"5")

if [ "$op" == "5" ]

then

echo "enter name of db"

read db

echo "enter id"

read id1

echo "enter line no u want to delete"

read linenumber

for line in $(grep -n "$id1" "$db")

do

number=$(echo "$line" | cut -c1)

if [ $number == $linenumber ]

then

lineRemove="${linenumber}d"

sed -i -e "$lineRemove" "$db"

echo "Record removed"

fi

done

cat "$db"

fi;;
"6")

echo "enter name of database you want to modify"

read db

if [ -f "$db" ]; then

echo "enter phone no you want to modify"

read ph

echo "enter new id"

read id1

echo "new name"

read nm

echo "enter new ph no "

read ph1

sed -i "/$ph/d" "$db"

echo "$id1 $nm $ph1">>"$db"

echo "recod modified successfully"

else

echo "db not found"

fi

;;

"7")

echo "bye"

;;

*)

echo "invalid input"

esac

done

You might also like