This is not very elegant, but here you go:
import re
start_ln = re.compile(r'\[\d+\] ppt: \(.*?\) \d+ \d+ (?P<ivar>\d+\.\d+\.\d+\.\d+)')
tstamp_ln = re.compile(r'timestamp: \d+')
state_ln = re.compile(r'states: (?P<pcount>\d+) (?P<ggroup>(\[\d+\(average \d+ \d+\)\])+)')
group_p = re.compile(r'\[(?P<st>\d+)\(average (?P<avg>\d+) \d+\)\]')
f = open('pfile', 'r')
state = 'WAIT'
llist = []
ldict = {}
cvar = None
for ln in f:
if state == 'WAIT':
mtch = start_ln.match(ln)
if mtch is not None:
cvar = mtch.groupdict()['ivar']
ldict = {}
state = 'LINE#1'
continue
elif state == 'LINE#1':
mtch = tstamp_ln.match(ln)
if mtch is not None:
ldict.update(mtch.groupdict())
state = 'LINE#2'
continue
elif state == 'LINE#2':
mtch = state_ln.match(ln)
if mtch is not None:
groupline = mtch.groupdict()['ggroup']
mtch2 = group_p.findall(groupline)
ldict[cvar] = dict(mtch2)
cvar = None
state = 'WAIT'
llist.append(ldict)
for i in llist:
print i
No error checking at all -- and the "state notation" is a bit superficial, but it should do the trick.