script to edit strings based on patterns

Hello All,

Here is the file which I want to edit. The script should look for DB2 and if found then delete all lines related to DB2 connection string. Is there way this can be done using script ?

DB1 =
(DESCRIPTION =
(SDU = 32768
(enable = broken)
(ADDRESS = (PROTOCOL = TCP)(HOST = myserver.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = myserver.com)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = DB1)
)
)
DB2 =
(DESCRIPTION =
(SDU = 32768)
(enable = broken)
(ADDRESS = (PROTOCOL = TCP)(HOST = anotherserver.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = anotherserver.com)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = DB2)
)
)
DB3 =
(DESCRIPTION =
(SDU = 32768)
(enable = broken)
(ADDRESS = (PROTOCOL = TCP)(HOST = thirdserver.com)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = thirdserver.com)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = DB3)
)
)

The code:

sed '/^DB2/,/DB2/ s/^/#/' < inputfile > outputfile && \
cp outputfile inputfile

Would comment out all the DB2 lines but would leave the "(" at the start and ")" at the end untouched, would that be any use?

sed '/^DB2/,/DB2/ d' < inputfile > outputfile && \
cp outputfile inputfile

Would delete all the DB2 lines but would leave the "(" at the start and ")" at the end untouched, would that be any use?

Are the entries always10 lines long? If they are, it's easy:

sed -i '/^DB2/,+9d' file

The -i switch edits in-place. But not all versions of sed support it, so if yours doesn't, you can do it the way TonyFullerMalv did.