Locate text in file then remove and replace

I'm trying to locate a block of text in a file, remove it and then replace with a new block.

I can find the first line number that the text starts on using grep -n. I then need to locate the ending line by searching for the string "}" that follows the line I found. Here's the steps I need to follow:

  1. Get line# of string "A" in file
  2. Get line# of string "B" based on starting line found in #1. (there are multiple occurences of this string, so I need to locate this string that not from the beginning of the file, but from the starting point that I found string A)
  3. Remove block of lines from #1 to #2 and replace with a new set of lines.

I know this is kinda complex, and will probably need an awk input file. I know awk, but not THAT well....

Thanks all!
Lloyd

Posting a snippet of the input and desired output will help a lot. When doing so, use

```text
 and 
```

tags to keep formatting and enhance readability, thanks.