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