Вы можете использовать Regex:
Ex:
import re
with open(filename, "r") as infile:
data = infile.read()
template = re.search("^TEMPLATE[^.]*", data, re.M).group()
print(re.findall("\s+(\d+)\s+", template, re.M))
print(re.findall("\s+(\d+)\;", template, re.M))
Выход:
['2548', '1', '2']
['0', '20', '20']