[Tutor] text processing, reformatting

Joel Goldstick joel.goldstick at gmail.com
Wed Dec 12 16:56:36 CET 2012


On Wed, Dec 12, 2012 at 9:34 AM, <lconrad at go2france.com> wrote:

>
> ...
>


> OPM010 HUNT INGR FRI 16/11/12 01:00:00 QRTR
> HTGP PEG OVFL
> 0012 00000 00000
> 0022 00000 00000
> 0089 00000 00000
> 0379 00000 00000
> OPM010 HUNT INGR FRI 16/11/12 01:15:00 QRTR
> HTGP PEG OVFL
> 0012 00000 00000
> 0022 00000 00000
> 0089 00000 00000
> 0379 00000 00000
>
> the engineer needs that reformatted into the "log line" the original
> machine should have written anyway, for importing into Excel:
>
> yyyy-mm-dd;hh:mm:ss;<htgp>;<**peg>;<ovfl>;
>

I'm guessing that you want output like this:

2012-11-16;01:15:00;0012;00000;00000
2012-11-16;01:15:00;0022;00000;00000
2012-11-16;01:15:00;0089;00000;00000
2012-11-16;01:15:00;0379;00000;00000


> With Bourne shell, I could eventually whack this out as I usually do, but
> as a Python pupil, I'd like to see how, learn from you aces and python
> could do it.   :)
>
>
The way the tutor list works generally is people come with specific coding
problems, show their code, and get help understanding what is wrong.  You
would do better here if you could show us what you have so far.

That being said, I hacked out about 15 lines of code that produced the
results I've shown above.  My code will work with any amount of data lines
if they are interspersed with your two header lines.

Python makes it easy to read a file line by line.  The lines contain end of
line characters, but python makes it easy to get rid of those (strip)
Your lines seem to have each column separated by spaces.  You can easily
split a line into a list
You can also identify the lines using str.startswith("HTGP"), etc.


> thanks
> Len
>
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121212/825adabe/attachment.html>


More information about the Tutor mailing list