I am trying to extract the text between that has specific text file:
----
data1
data1
data1
extractme
----
data2
data2
data2
----
data3
data3
extractme
---
This works well enough for me. Your sample data is in a file called "data.txt" and the output goes to "result.txt"
inFile = open("data.txt")
outFile = open("result.txt", "w")
buffer = []
keepCurrentSet = True
for line in inFile:
buffer.append(line)
if line.startswith("----"):
#---- starts a new data set
if keepCurrentSet:
outFile.write("".join(buffer))
#now reset our state
keepCurrentSet = False
buffer = []
elif line.startswith("extractme"):
keepCurrentSet = True
inFile.close()
outFile.close()