I am trying to extract the text between that has specific text file:
----
data1
data1
data1
extractme
----
data2
data2
data2
----
data3
data3
extractme
---
For Python2
#!/usr/bin/env python
with open("infile.txt") as infile:
with open("outfile.txt","w") as outfile:
collector = []
for line in infile:
if line.startswith("----"):
collector = []
collector.append(line)
if line.startswith("extractme"):
for outline in collector:
outfile.write(outline)
For Python3
#!/usr/bin/env python3
with open("infile.txt") as infile, open("outfile.txt","w") as outfile:
collector = []
for line in infile:
if line.startswith("----"):
collector = []
collector.append(line)
if line.startswith("extractme"):
for outline in collector:
outfile.write(outline)