0% found this document useful (0 votes)
24 views3 pages

Ass 1

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

Ass 1

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

ASSIGNMENT:-1

echo "Enter file name:"

read fname

opt=0

while [ $opt -ne 6 ]

do

echo "Enter choice:\n1)create \n2)display \n3)search \n4)delete \n5)modify \n6)exit\n\


tenter choice:"

read opt

case $opt in

1)

echo "Enter first Name:"

read name

echo "Enter last Name:"

read lname

echo "mobile number:"

read mobno

echo "address:"

read address

echo $id $name $lname $mobno $address >> $fname

;;

2)

cat $fname

;;

3)

echo "Enter text to search:"

read sname

grep -i $sname $fname

;;

4)

echo "Enter name of the record to DELETE:"

read dname
if grep -q $dname $fname ;

then

grep -v $dname $fname > $fname.tmp && mv $fname.tmp $fname

echo "entry with name $dname deleted"

else

echo "entry with name $dname not found"

fi

;;

5)

echo "line number to modify: "

read start

echo "Before text :"

read before

echo "After text :"

read after

if grep -q $before $fname ;

then

sed -i "$start,+1 s|$before|$after|g" $fname

echo "$before updated to $after"

else

echo "record of '$before' not found"

fi

;;

6)

echo "Exiting..."

;;

*)

echo "Invalid option. Please select a number between 1 and 6."

;;

esac

done
Output:-

Enter file name: 4


address Enter name of the record to DELETE:
Enter choice: Elon
1)create entry with name Elon deleted
2)display Enter choice:
3)search 1)create
4)delete 2)display
5)modify 3)search
6)exit 4)delete
enter choice: 5)modify
2 6)exit
Lorem Ipsum 9089089088 Mumbai enter choice:
John Doe 7878787878 Delhi 5
Jack Marks 9089087777 Calcutta line number to modify:
1
Enter choice: Before text :
1)create Mumbai
2)display After text :
3)search Surat
4)delete Mumbai updated to Surat
5)modify Enter choice:
6)exit 1)create
enter choice: 2)display
1 3)search
Enter first Name: 4)delete
Elon 5)modify
Enter last Name: 6)exit
Musk enter choice:
mobile number: 2
8888888880 Lorem Ipsum 9089089088 Surat
address: John Doe 7878787878 Delhi
Chennai Jack Marks 9089087777 Calcutta
Enter choice:
1)create Enter choice:
2)display 1)create
3)search 2)display
4)delete 3)search
5)modify 4)delete
6)exit 5)modify
enter choice: 6)exit
3 enter choice:
Enter text to search: 6
John Exiting...
John Doe 7878787878 Delhi
Enter choice:
1)create
2)display
3)search
4)delete
5)modify
6)exit
enter choice:

You might also like