Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help on parsing fixed-width file and update DB

Status
Not open for further replies.

lizok

Programmer
Jan 11, 2001
82
US
Hello, i am trying to parse an uploaded file which is a fixed-width format. I have predefined length for each field and the number of fields. What would be the best approach/technique to accomplish this?

example:
ID- 11 chars
Year -4 chars
SSN-9 chars
LastName-20chars
Firstname-10 chars

the file will look like this:
P01234567892005999999999Doe Jane
P01234567882005888888888Doe John
 
use a database to view the file as an external table and query the db.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
It's time to play with the Left() and Right() functions! :)

For example:
Code:
<cfset MyVar = "P01234567892005999999999Doe                 Jane      ">

To get the first 11 characters as the ID:
<cfset ID = Left(MyVar, 11)>

To get the Year:
<cfset Year = Right(Left(MyVar, 15),4)>

Now, with that being said, I'm not sure how CF will handle all of the extra spaces added in around the first and last name.  So, this may or may not work:

<cfset FirstName = Right(MyVar, 10)>


Hope This Helps!

ECAR
ECAR Technologies, LLC

"My work is a game, a very serious game." - M.C. Escher
 
lol. well, if the db can't read fixed width files or there are too many files, or uncontrolled file names i was going to go your rout so between the 2 of us i think we nailed it pretty good :)

good job [thumbsup]

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
TruthInSatire,
What do you mean by "use a database to view the file as an external table and query the db. " ?

liz
 
some databases often have wizards to import or view text files as a table. Access for example has that ability.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top