awk script issue redirecting to multiple files after matching pattern

Hi All

I am having one awk and sed requirement for the below problem.
I tried multiple options in my sed or awk and right output is not coming out.

Problem Description

###############################################################

I am having a big file say file having repeated patterns . I want to print the text in between these patters along with these patterns in multiple text files means I want to redirect the output to multiple text files.

file

############################################################

///// BMSNSMS ,.KSKSK
/// BM_WATER//////////
///JSHSHS L;LLLLLLLL
module Template 
input {
}
output { B 
}
port {  se 

}
///// NANAMSNSMS ,.KSKSK
/// BM_WATER//////////
///jajaJSHSHS L;LLLLLLLL
module1 Template1 
input1 {
}
output1 { B 
}
port{  se 

}
port {
C

}
///// KLALALNANAMSNSMS ,.KSKSK
/// BM_WATER//////////
///KAKAjajaJSHSHS L;LLLLLLLL
module2 Template2 
input2 {
}
output2 { CD 
}
port3{  se 

}
port {
D

}
///// AAKLALALNANAMSNSMS ,.KSKSK
/// BM_WATER//////////
///aaKAKAjajaJSHSHS L;LLLLLLLL
module3 Template3
input3 {
}
output3 { CD 
}
port4{  se 

}
port1 {
D

}

###############################################################

So we can see that BM_WATER is a repeated pattern
I want output as shown below

File1
###################################

///// BMSNSMS ,.KSKSK
/// BM_WATER//////////
///JSHSHS L;LLLLLLLL
module Template 
input {
}
output { B 
}
port {  se 

}

File 2

///// NANAMSNSMS ,.KSKSK
/// BM_WATER//////////
///jajaJSHSHS L;LLLLLLLL
module1 Template1 
input1 {
}
output1 { B 
}
port{  se 

}
port {
C

}

FILE 3

///// KLALALNANAMSNSMS ,.KSKSK
/// BM_WATER//////////
///KAKAjajaJSHSHS L;LLLLLLLL
module2 Template2 
input2 {
}
output2 { CD 
}
port3{  se 

}
port {
D

}

FILE 4

///// AAKLALALNANAMSNSMS ,.KSKSK
/// BM_WATER//////////
///aaKAKAjajaJSHSHS L;LLLLLLLL
module3 Template3
input3 {
}
output3 { CD 
}
port4{  se 

}
port1 {
D

}

I tried this but not working

awk '/BM_WATER/{x="F"++i;}{print > x;}' file

Hello kshitij,

Following may help you in same.

awk '{if($0 ~ /^\/\/\/\/\/.*/){i++;while($0 !~ /^port.*\{/){print $0 >> "File"i".txt";getline}};}' Input_file

Thanks,
R. Singh

Hi Ravinder ,

Thanks for the reply
I tried this but it is not generating output files properly all the port statements are missing in the new output files
Can you help me out with revised script

Thanks
Kshitij

Try

awk '$0~"^/////"{FN="FILE"++CNT} {print > FN}' file

Hi
Thanks but I need to match it with BM_WATER to split into multiple files.
Thanks
Kshitij