I have a large log with several commands (ending with ;) and their outputs (till END) like the following:
<blabla;
foo
...
...
END
<xyz;
...
...
END
--and so on
The requirement is to have separate files with command names like
blabla
xyz
and in each file should be their respective outputs.
So far I have:
def generateDicts(log_fh):
currentDict = {}
for line in log_fh:
if line.endswith(";"):
if line.endswith("END"):
yield currentDict
currentDict = {""}
else:
currentDict["text"] += line
yield currentDict
with open("logfile.txt") as f:
print list(generateDicts(f))
Please help.