converting text file to csv

p 4 p41600 at hotmail.com
Tue Oct 29 22:59:43 CET 2002


Hi,
I am new to Python and want to knwo the best way to convert the following 
file: to the one at the bottom (CSV file)
Attached is a copy of the sample.
Thanks
Header1 zxc  sadf sdaf asdf  OCT25 09:00:00 61000 sdfgj ashsa asdkj
        Header1 cont
        Header1 cont
        Header 1 cont

        Data_Type1
           Key name
              Tx   num1   num2
                  Value1      value2    value3     value4     value5     
value6
                 Value11     value12   value13    value14    value15    
value16
                 Value33

          12 sensor_1
             2x    99    56
                       0          0          0          0          0         
  0
                       0          0          0          0          0         
  0
                       0

          80 sensor_x
             2m    60   190
                       0          0          0          0          0         
  0
                       0          0          0          0          0         
  0
                       0

          58 sensor_y
             2W   102   309
                       0          0          0          0          0         
  0
                       0          0          0          0          0         
  0
                       0
     ...
     ...
        Data_Type2
           Key
                  Valu41      valu42    valu43     valu44     valu55     
valu56
                 Value71     value82   value93

          12
                       0          0          0          0          0         
  0
                       0          0          0

     ...
     ...
        Data_Type3
           Key
                  Valu41      valu42    valu43     valu44     valu55     
valu56
                 Value71     value82   value93     value32   value97

          50
                       0          0          0          0          0         
  0
                       0          0          0          0          0

          90
                       0          0          0          0          0         
  0
                       0          0          0          0          0

          51
                       0          0          0          0          0         
  0
                       0          0          0          0          0

          14
                       0          0          0          0          0         
  0
                       0          0          0          0          0
     ...
     ...

Header1 zxc  sadf sdaf asdf  OCT25 09:00:00 61000 sdfgj ashsa asdkj
        Header1 cont
        Header1 cont
        Header 1 cont

        Data_Type1
           Key name
              Tx   num1   num2
                  Value1      value2    value3     value4     value5     
value6
                 Value11     value12   value13    value14    value15    
value16
                 Value33

          12 sensor_1
             2x    99    56
                       0          0          0          0          0         
  0
                       0          0          0          0          0         
  0
                       0

          80 sensor_x
             2m    60   190
                       0          0          0          0          0         
  0
                       0          0          0          0          0         
  0
                       0

          58 sensor_y
             2W   102   309
                       0          0          0          0          0         
  0
                       0          0          0          0          0         
  0
                       0
     ...
     ...
        Data_Type2
           Key
                  Valu41      valu42    valu43     valu44     valu55     
valu56
                 Value71     value82   value93

          12
                       0          0          0          0          0         
  0
                       0          0          0

     ...
     ...
        Data_Type3
           Key
                  Valu41      valu42    valu43     valu44     valu55     
valu56
                 Value71     value82   value93     value32   value97

          50
                       0          0          0          0          0         
  0
                       0          0          0          0          0

          90
                       0          0          0          0          0         
  0
                       0          0          0          0          0

          51
                       0          0          0          0          0         
  0
                       0          0          0          0          0

          14
                       0          0          0          0          0         
  0
                       0          0          0          0          0
     ...
     ...


and it needs to be converted to:

Header1,zxc,sadf,sdaf,asdf,OCT25,09:00:00,61000,sdfgj,ashsa,asdkj,Header1,cont,Header1,cont,Header,1,cont
Data_Type1
Key,name,Tx,num1,num2,Value1,value2,value3,value4,value5,value6,Value11,value12,value13,value14,value15,value16,Value33
12,sensor_1,2x,99,56,0,0,0,0,0,0,0,0,0,0,0,0,0
80,sensor_x,2m,60,190,0,0,0,0,0,0,0,0,0,0,0,0,0
58,sensor_y,2W,102,309,0,0,0,0,0,0,0,0,0,0,0,0,0
...
...
Data_Type2
Key,Valu41,valu42,valu43,valu44,valu55,valu56,Value71,value82,value93
12,0,0,0,0,0,0,0,0,0
...
...
Data_Type3
Key,Valu41,valu42,valu43,valu44,valu55,valu56,Value71,value82,value93,value32,value97
50,0,0,0,0,0,0,0,0,0,0,0
90,0,0,0,0,0,0,0,0,0,0,0
51,0,0,0,0,0,0,0,0,0,0,0
14,0,0,0,0,0,0,0,0,0,0,0
...
...
Header2,zxc,sadf,sdaf,asdf,OCT25,09:05:00,61000,sdfgj,ashsa,asdkj,Header2,cont,Header2,cont,Header2,1,cont
Data_Type1
Key,name,Tx,num1,num2,Value1,value2,value3,value4,value5,value6,Value11,value12,value13,value14,value15,value16,Value33
12,sensor_1,2x,99,56,0,0,0,0,0,0,0,0,0,0,0,0,0
80,sensor_x,2m,60,190,0,0,0,0,0,0,0,0,0,0,0,0,0
58,sensor_y,2W,102,309,0,0,0,0,0,0,0,0,0,0,0,0,0
...
...
Data_Type2
Key,Valu41,valu42,valu43,valu44,valu55,valu56,Value71,value82,value93
12,0,0,0,0,0,0,0,0,0
...
...
Data_Type3
Key,Valu41,valu42,valu43,valu44,valu55,valu56,Value71,value82,value93,value32,value97
50,0,0,0,0,0,0,0,0,0,0,0
90,0,0,0,0,0,0,0,0,0,0,0
51,0,0,0,0,0,0,0,0,0,0,0
14,0,0,0,0,0,0,0,0,0,0,0
...
...






_________________________________________________________________
Unlimited Internet access -- and 2 months free!  Try MSN. 
http://resourcecenter.msn.com/access/plans/2monthsfree.asp
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: logexample.txt
URL: <http://mail.python.org/pipermail/python-list/attachments/20021029/b9648afe/attachment.txt>


More information about the Python-list mailing list