On Thu, 07 Nov 2002 12:25:12 -0800, [EMAIL PROTECTED] (John W. Krahn) wrote:

Thank you very much John.
....
>> My file is ~350MB. (not attached of course)
>> It has the structure as shown in the attachment [OrderSample.txt].
>> I have also attached an example of what the data should look like in
>> final form [OrderSampleFinished.txt].
>
>The two files in the other message aren't labeled and it isn't clear
>which is relevant ...
>
...
Sorry for the confusion.  There were 2 files attached. One showed the file that
I am trying to extract data from [OrderSample.txt].  This is transaction data
from an order processing system.

The second file is what I would like the output to look like so I can import
(tab delimited) into a database.  In this case I'll try MS Access unless it
cacks.
...
>> Each record spans 3 lines.
>> 
>> I am using ActivePerl.
>> 
>> #!c:\perl\perl -n
>> 
>> use strict;
>> 
>> while(/^Customer\:[ \t]+([\*\d+)[ \t]+(.+)/){
>>         chomp;
>>         my $customer = substr($_,2);
>>         while(/^([\*\d+|\d+][ \t]+([\d+])[ \t]([\d{2}\/[\d{2}\/[\d{2})
>> ... select to end of third line)
>>         my $order = substr($_,19)
>>                 while (<>){
>>                         next LINE if ($order(2) eq $order(2));
>>                         print "$customer$_" ""$order$_" > newfile.txt;
>>                 }
>>         }
>> }
>> 
>> I'm not sure if while is going to work or if I should try to figure
>> out how to use foreach?
>
>If you don't know how to describe what you want to do in Perl, try to
>describe it in English.
...
OK, I will try in English
I want to extract all the transactional data from the file and put into tab
delimited format so I can import into a database.

Each page has a header with the customer information.  Then there is a
description of the item purchased.  The item description shows up only at the
start of a list of orders for each customer.  Then there is the order
transaction data that shows the qty and date of the order plus some other info
but doesn't show the item number or description

I want to create a record for each order which has the customer info, item info
and order info.

So in psydo code;

Open  the file "file.txt"


if line starts with "Customer"
        then capture and store "Customer Number" and "Customer Name"
        increment to next line and do ItemNumberCapture for all items and orders
else
        increment to next line
endIf

ItemNumberCapture
if line begins with "Item Number" and contains "Item Descriptions"
        then capture and store "Item number" "item descriptions" and rest of "3
line item record"
        write record to external file
        increment to next line
else    #for lines that only have order data
        capture and store order transaction data
        write record to external file
endIf

I hope this makes sense
Philip

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to