Question

Best way to parse mixed variable and fixed width text file


I have a large number of text files of traffic count locations that contain both header information with necessary attribute fields and 2 fixed width sets of data that I also need to bring in as attributes. I am looking to ultimately create a table where the info from each text file is one row/feature in the table so I can join it to an existing point feature class with the Reference Number being the join field. I could do multiple tables if I have to also.

 

I can't seem to figure out a good way to get both the Header attributes as well as the fixed width attributes.

 

A sample of one of the text files:

00011650They are actually .tam, .tpm and .tms files (no idea what those file formats actually are and google was not really any help) but they can be read as .txt files. I have attached one that I saved as a .txt as a sample


3 replies

Userlevel 1
Badge +21

Does the fixed width data always start at the same line number in the file?

Does the fixed width data always start at the same line number in the file?

both sets of fixed width "tables" in the files seem to start at the same lines (and end at the same lines) in all of the files I have looked at so far

Userlevel 5
Badge +29

I've attached an example, the basic gist of it is use a text file reader and string searcher to pull out the header info, then use a CSV reader to pull out the tabular data

 

 

Reply