Jump to content

Convert text to table


sbrinley

Recommended Posts

I'm trying to take a block of text that is formatted very poorly and put it into something that is more database friendly. Here is an example of the text:

 

----------------------------------------------------------------------------------------------------------------------------------


Albert, Kyle                     050359     92501    Temp sunshade          
         ID IN   Dept   ACTIVITY       OUT    ID IN   Dept   ACTIVITY       OUT      TOTALS
Mon 01/04   553a                       611p                                        12.00   12.00
Tue 01/05   552a                       603p                                        12.00   24.00
Wed 01/06   558a                       647p*L                                      12.00   36.00
Thu 01/07   632a*L                     909a*E                                       2.60   38.60

  Acct:92501  
                    TempRg:     38.60
     


----------------------------------------------------------------------------------------------------------------------------------


Aldridge,Jennie M                0001090916 026991   Plt 2 Shipping         
         ID IN   Dept   ACTIVITY       OUT    ID IN   Dept   ACTIVITY       OUT      TOTALS
Mon 01/04   538a                       431p                                        10.00   10.00
Tue 01/05   541a                       431p                                        10.00   20.00
Wed 01/06   541a                       448p                                        10.00   30.00
Thu 01/07   547a                                                                    5.00   35.00

  Acct:026991 
                       REG:     35.00
     


----------------------------------------------------------------------------------------------------------------------------------


 

The goal is to get it to look something like this:

 

Name ID Workcenter Date  hrs worked

Albert, Kyle  050359 92501 01/04/10  12

Albert, Kyle  050359 92501 01/05/10  12

Albert, Kyle  050359 92501 01/06/10  12

Albert, Kyle  050359 92501 01/07/10  2

Aldridge,Jennie  0001090916 026991 01/04/10  10

Aldridge,Jennie  0001090916 026991 01/05/10  10

Aldridge,Jennie  0001090916 026991 01/06/10  10

Aldridge,Jennie  0001090916 026991 01/07/10  5

 

The data will always be in the same place in the file. I'm not even sure what method would work to go through the the file to make this happen.

 

I'm not exactly looking for a complete answer but more of a nudge in the right direction.

Link to comment
Share on other sites

use file() and put it into an array. Set a counter and loop through looking for dashed lines. When you find one stuff all the lines into an array using the counter as the key, stop when you hit another dashed line and start again. When your done with the file you are going to have an array with each block as an array. You can then loop through and figure out what you need to do to each line to get what you need.

 

 

HTH

Teamatomic

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.