Replacing text between two patterns

I would like to replace ], with ]]], between /* SECTION2-BEGIN / and / SECTION2-END */ in my file. My file contains the following information:

/* SECTION1-BEGIN */
                      ['example',    'example.txt'],
/* SECTION1-END */

/* SECTION2-BEGIN */
                      ['test1',      'show.txt'],
/* SECTION2-END */

/* SECTION3-BEGIN */
                      ['random',     'gone.html'],
/* SECTION3-END */

The new changed text would look like:

/* SECTION2-BEGIN */
                      ['test1',      'show.txt']]],
/* SECTION2-END */
perl -pe 'if(/SECTION2-BEGIN/../SECTION2-END/){s/\]/]]]/g}' file
1 Like

How about:

sed '/SECTION2-BEGIN/,/SECTION2-END/s/]/]]]/g' infile
1 Like

Now I can't figure out how to replace the last ], with ]]],

/* SECTION1-BEGIN */
                      ['example',    'example.txt'],
/* SECTION1-END */

/* SECTION2-BEGIN */
                      ['test1',      'show.txt'],
/* SECTION2-END */

/* SECTION3-BEGIN */
                      ['random',     'gone.html'],
/* SECTION3-END */

The changed code should look like this:

/* SECTION1-BEGIN */
                      ['example',    'example.txt'],
/* SECTION1-END */

/* SECTION2-BEGIN */
                      ['test1',      'show.txt'],
/* SECTION2-END */

/* SECTION3-BEGIN */
                      ['random',     'gone.html']]],
/* SECTION3-END */

How about 2 -> 3

** Removed ** See issue below

---------- Post updated at 04:23 AM ---------- Previous update was at 04:21 AM ----------

So this works well for changing a single closing bracket to three closing brackets between 2 specified strings in a file:

sed -i test -e '/TOOLS-BEGIN/,/TOOLS-END/s/]/]]]/g'

I have a new issue once again. What I would like to do now is change the 5th occurrence of a single closing bracket to three closing brackets. Starting from for example SECTION2-END until lets say SECTION15-END. So the 5th bracket would be changed to ]]]

Thank you for any help.