any savant ? using AWK/SED to remove newline character between two strings : conditional removal

I'd like to remove (do a pattern or precise replacement - this I can handle in SED using Regex )
---AFTER THE 1ST Occurrence ( i.e. on the 2nd occurrence - from the 2nd to fourth occurance ) of a specific string : type 1
-- After the 1st occurrence of 1 string1 till the 1st occurrence of string2 not counting the latter.

e.g.

Begin Transaction ;
She sells
sea shells 
by 
the 
sea shore
End Transaction ;

Begin Transaction ;
For if she sells sea-shells on the sea-shore
 Then I'm sure she sells sea-shore shells.
End transaction ;


Begin Transaction ;
The shells sh
e sells a
re sea-sh
ells, I'm s
ure.

/* Notice How I made the above English incoherent by putting newline breaking words, those newline need to go */
End Transaction ;

replace function () 
Blah
  • How do I go about knocking of the newline char between Last Begin and End transaction pair
    Program Thought : Go find the 3rd Begin transaction statement and knock off the newline until the 1st end transaction statement

Try:

awk -vRS= 'NR==3{gsub("\n","")}1' file

Two approaches:

awk '/^End [Tt]ransaction/&&g==3{print "";g++}g==3{printf $0; next}/^Begin Transaction/{g++} 1' infile
awk 'NR==3{f=split($0,A,"\n");print A[1];for(i=2;i<f;)printf A[i++];$0="\n"A[f]} $0=$0"\n"' RS= infile

Both the 2nd solution here and bartus11's post above rely on a blank line after the End line. Unlike Bartus11's solution the 2nd solution here ensures the Beg and End lines aren't joined up with the rest of the text, and restores the blank line after then End line.

That was very helpful except for the fact that it does not 'think' like this .
What I am trying to do is getting rid of the newline characters - that erroneously break the word and make things incoherent.
LOGIC:

-- Go Find a String1
---Look for the nth instance of String1
-- From the nth instance onwards , excluding string1 : `do this stuff`
-- Keep doing till you come to the 'm th' instance of string 2 , excluding String2.
The above was a brilliant idea , except for the fact that I cannot gurantee that there is a paragraph in every file , that can be used as line separator
So your looking at something like this :

Begin Transaction ;
She sells
sea shells
by
the
sea shore
End Transaction ;
Begin Transaction ;
For if she sells sea-shells on the sea-shore
 Then I'm sure she sells sea-shore shells.
End transaction ;
Begin Transaction ;
The shells sh
e sells a
re sea-sh
ells, I'm s
ure.
replace function ()
Blah


Output should be :

Begin Transaction ;
She sells
sea shells
by
the
sea shore
End Transaction ;
Begin Transaction ;
For if she sells sea-shells on the sea-shore
 Then I'm sure she sells sea-shore shells.
End transaction ;
Begin Transaction ;
The shells she sells are sea-shells, I'm sure.
replace function ()
Blah


.The above AWK gives this o/p

Begin Transaction ;
She sells
sea shells
by
the
sea shore
End Transaction ;
Begin Transaction ;
For if she sells sea-shells on the sea-shore
 Then I'm sure she sells sea-shore shells.
End transaction ;
/* there is no newline char after the begin transaction below. It shd be there * /
Begin Transaction ;The shells she sells are sea-shells, I'm sure.
replace function ()
Blah

THANKS for your help

My solution #1 (no dependance on blank lines) produces the following output for your 2nd example:

Begin Transaction ;
She sells
sea shells
by
the
sea shore
End Transaction ;
Begin Transaction ;
For if she sells sea-shells on the sea-shore
 Then I'm sure she sells sea-shore shells.
End transaction ;
Begin Transaction ;
The shells she sells are sea-shells, I'm sure.replace function ()Blah

How is the program to know to stop joining lines at replace function () ? Should it to stop joining once a fullstop char (".") is encountered?