I am trying to split a file each time that there are exactly 4 integers followed by a space on a line in ht efile. I think I am almost there (looking at all questions and examples). Think I need a last push. Could anyone help me out.
The script splits all lines that start with 4 integers. It needs to only split when its just 4 integers and not more then 4.
import re
file = open('test.txt', 'r')
Try 1
for x in file.read().split(re.match(r"[0-9]{4}\s", file.readline())):
print (x)
Try 2
for x in file.read().split(re.match(r"[0-9][0-9][0-9][0-9]\s", file.readline())):
print (x)
try 3
for x in re.split(r"[0-9]{4}\s", file.read()):
print (x)
Sample input
1020
200123242151111231 bla bla bla
200123331231231441 bla bla bla
1030
200123242151111231 bla bla bla
200123331231231441 bla bla bla
Wished for output is the above content split in:
200123242151111231 bla bla bla
200123331231231441 bla bla bla
and
200123242151111231 bla bla bla
200123331231231441 bla bla bla