I have a huge text file with below format (as an ASCII file). I am using python for processing the same. For this kind of files, I have few questions (in more generic way).
- How do I check the correctness of the data format? Is there a way to specify a template and then verify the correctness for such text files? (similar to a dtd file of an xml).
- Second question is parsing such file and reading data from the file. Like I expect
XYZdata to come after thetimerow and would need to parse them. Any simple mechanism for such scenarios? Again like a template and parse mechanism.
===========================BEGIN=========================================
2012-12-05 12:03
XYZ 123(0) 654(2) 232(4)
MON 23(0) 54(2) 32(4)
POR 13(0) 64(1) 92(2)
=========================== END =========================================
===========================BEGIN=========================================
2012-12-05 12:04
XYZ 123(0) 654(2) 232(4)
MON 23(0) 54(2) 32(4)
POR 13(0) 64(1) 92(2)
=========================== END =========================================
===========================BEGIN=========================================
2012-12-05 12:05
XYZ 523(0) 654(2) 235(4)
MON 83(0) 54(2) 32(4)
POR 13(0) 64(1) 92(2)
=========================== END =========================================
===========================BEGIN=========================================
2012-12-05 12:03
XYZ 193(0) 644(2) 232(4)
MON 23(0) 54(2) 32(4)
POR 13(0) 64(1) 92(2)
=========================== END =========================================
You could try a variation of the following :-
This prints :-