Click to See Complete Forum and Search --> : parse/pull-out data from a text file


Metroid
03-24-2005, 11:51 AM
I have a text file that I need to pull information out of but it is set up in a very strange way. How would I start this process? It is not a comma but tab (once again information isn't set up in a logical way). Any guidance would be appreciated.

Thanks

NogDog
03-24-2005, 12:08 PM
Tab-delimiting is no problem. With most scripting languages there is a method to read in a text file a line at a time. You can then use some sort of "split" function to break the line on a selected character (in this case the tab), which populates an array with each successive array element being one part of the line which was delimited by that character. You can then use various text pattern-matching functions to analyze the elements and do whatever you need to do. That's about all I can say without knowing the actual structure of your data file.

Metroid
03-24-2005, 02:34 PM
Hey NogDog...Thanks for the response. I figured out that the file is Fixed-length. I also figured it will be easier to use ADO instead of the FileSystemObject. Now I just have to figure out how to write this thing. The problem is that the information is set up in a column format but with different information in each line of the column. I need to break that information out and place it in a table.

Metroid
03-29-2005, 06:05 PM
Not sure if this is the correct forum but I have a rather complicated file. It is a tab delimited text file that has data on several rows per column. I am stuck.
Also, some of the data needs to precede some data that is below it. So I would need a statement to check if this is there and if so move it to its own column in the database. :(

I have read the best way to do this is to use ADO with VB. Is this the best way?

I have no control how the information comes to me but really need some guidance on this one.

Thanks-in-advance

NogDog
03-29-2005, 10:33 PM
Well, since I've never really worked with VB and don't even know what ADO is, I'd probably do it in Perl (which has a lot of text parsing capabilities). Whatever you use, sounds like you'll need to set a number of "flag" variables to indicate the current "state" of the file being parsed. For instance, if "xxxxxx" at the beginning of a line is required before the "yyyyyy" data on the next line, then when you find "xxxxxxx" you set some flag variable, let's call it $x_set, to TRUE. (Therefore, you'd probably initiate to FALSE at the start of the program.) Then you'll have to have conditional statements that determine how to parse a line based on which flags are set.