Loop through fields in an import file?
Jose Lerebours
fpgroups at gmail.com
Wed Feb 9 07:38:32 PST 2011
On Wed, Feb 9, 2011 at 9:25 AM, Mike Schwartz <mschw at athenet.net> wrote:
> Using filePro 5.0.14 on Linux, I am trying to import a pipe-delimited
> text file that has 331 fields in it. I'm writing the data into a filePro
> file that has 331 fields that are laid out exactly like the import file.
>
>
>
> import ascii infile = (@pm) f=| r =\n
>
>
>
> lookup ofile = cust2 r=free -n
>
>
>
> I'd prefer not to write 331 "ofile(1)=infile(1)" style statements, but
> I can't think of a way to write a loop that will loop 331 times to write all
> the import fields to the output file.
>
>
>
> I declared fcount(3,.0) = "1" and then wrote a loop that included
> ofile(fcount)=infile(fcount), but filePro gave me a syntax error on that,
> pointing to the "f" in infile(fcount).
>
>
>
> I thought about importing each data record as one long string (ignoring
> the pipes) and then parsing the string for pipes, but that's a lot of extra
> work.
>
>
>
> Or, instead of using "import", I could also "open" the file and use
> readline to process the data, but I would still have to parse for the pipes.
>
>
>
>
> However, before I sit down and write a lot of complex code, is there
> some simple 1-liner method to loop through and move these 331 fields into
> the output file?
>
>
Well, I would change the import to load the entire record into a
single field like so:
import ascii infile = (@pm) f=\n r =\n
Then write the filepro code, a few lines, to parse through the field
and extract the columns using instr() and mid() functions to point at
the columns searching string "|"
This seems simple enough! What say you?
Regards,
Jose Lerebours
954 559 7186
More information about the Filepro-list
mailing list