C
Chip
Hi and thanks for reading this post.
I have a text file that I need to convert
from a vertical list to a horizontal comma
delimited file that will always have the
same number (12) items in it.
The first item in each line is a serial
number that is always 17 characters followed
by a model number, stock number, sale price,
cost, color, then a list of options which
can vary between 1 to 6.
I can split the vertical file on the "\n"
but will need a loop to add blank fields
to the end of the line if the options
do not total 6 so that the line always
has total of 12 fields even if there are
not a total of 6 options.
$filename = "vertical.txt";
open(FILE, "$filename") || die "Could not open $filename";
@array = <FILE>;
foreach $line (@array)
{
if ( $line =~ /[^\S{17}]/) #serial number
{
#code to make formatted file
}
}
Thanks for your time and any and all help
is appreciated.
Chip
Example files;
<vertical.txt>
2G1WF52E849457786
1WF19
9457786
24600.00
22988.78
White/Lt Gray/cloth
B34 FLOOR MATS
FE9 FEDERAL EMISSION EQUIPMENT
K34 ELECTRONIC SPEED CONTROL
2G1WF52EX49457241
1WF19
9457241
22725.00
21282.53
White/Light Gray Clth
B34 FLOOR MATS
FE9 FEDERAL EMISSION EQUIPMENT
K34 ELECTRONIC SPEED CONTROL
LA1 3.4 V6 ENGINE
MX0 4 SPEED AUTO W/OVERDRIVE
2G1WP551449281308
1WP19
9281308
32835.00
30542.19
Black/Lt Gray Leather
AW6 DRIVERS SIDE AIRBAG
CF5 ELECTRIC SUNROOF
FE9 FEDERAL EMISSION EQUIPMENT
L67 SUPERCHARGED 3.8L SFI V6
MX0 4 SPEED AUTO W/OVERDRIVE
UP0 AM/FM CASS/CD PLAYER
</vertical.txt>
<formatted file>
2G1WF52E849457786,1WF19,9457786,24600.00,22988.78,White/Lt Gray/cloth,B34
FLOOR MATS,FE9 FEDERAL EMISSION EQUIPMENT,K34 ELECTRONIC SPEED CONTROL,,,,
2G1WF52EX49457241,1WF19,9457241,22725.00,21282.53,White/Light Gray Clth,B34
FLOOR MATS,FE9 FEDERAL EMISSION EQUIPMENT,K34 ELECTRONIC SPEED CONTROL,LA1
3.4 V6 ENGINE,MX0 4 SPEED AUTO W/OVERDRIVE,,
2G1WP551449281308,1WP19,9281308,32835.00,30542.19,Black/Lt Gray Leather,AW6
DRIVERS SIDE AIRBAG,CF5 ELECTRIC SUNROOF,FE9 FEDERAL EMISSION EQUIPMENT,L67
SUPERCHARGED 3.8L SFI V6,MX0 4 SPEED AUTO W/OVERDRIVE,UP0 AM/FM CASS/CD
PLAYER,
</formatted file>
I have a text file that I need to convert
from a vertical list to a horizontal comma
delimited file that will always have the
same number (12) items in it.
The first item in each line is a serial
number that is always 17 characters followed
by a model number, stock number, sale price,
cost, color, then a list of options which
can vary between 1 to 6.
I can split the vertical file on the "\n"
but will need a loop to add blank fields
to the end of the line if the options
do not total 6 so that the line always
has total of 12 fields even if there are
not a total of 6 options.
$filename = "vertical.txt";
open(FILE, "$filename") || die "Could not open $filename";
@array = <FILE>;
foreach $line (@array)
{
if ( $line =~ /[^\S{17}]/) #serial number
{
#code to make formatted file
}
}
Thanks for your time and any and all help
is appreciated.
Chip
Example files;
<vertical.txt>
2G1WF52E849457786
1WF19
9457786
24600.00
22988.78
White/Lt Gray/cloth
B34 FLOOR MATS
FE9 FEDERAL EMISSION EQUIPMENT
K34 ELECTRONIC SPEED CONTROL
2G1WF52EX49457241
1WF19
9457241
22725.00
21282.53
White/Light Gray Clth
B34 FLOOR MATS
FE9 FEDERAL EMISSION EQUIPMENT
K34 ELECTRONIC SPEED CONTROL
LA1 3.4 V6 ENGINE
MX0 4 SPEED AUTO W/OVERDRIVE
2G1WP551449281308
1WP19
9281308
32835.00
30542.19
Black/Lt Gray Leather
AW6 DRIVERS SIDE AIRBAG
CF5 ELECTRIC SUNROOF
FE9 FEDERAL EMISSION EQUIPMENT
L67 SUPERCHARGED 3.8L SFI V6
MX0 4 SPEED AUTO W/OVERDRIVE
UP0 AM/FM CASS/CD PLAYER
</vertical.txt>
<formatted file>
2G1WF52E849457786,1WF19,9457786,24600.00,22988.78,White/Lt Gray/cloth,B34
FLOOR MATS,FE9 FEDERAL EMISSION EQUIPMENT,K34 ELECTRONIC SPEED CONTROL,,,,
2G1WF52EX49457241,1WF19,9457241,22725.00,21282.53,White/Light Gray Clth,B34
FLOOR MATS,FE9 FEDERAL EMISSION EQUIPMENT,K34 ELECTRONIC SPEED CONTROL,LA1
3.4 V6 ENGINE,MX0 4 SPEED AUTO W/OVERDRIVE,,
2G1WP551449281308,1WP19,9281308,32835.00,30542.19,Black/Lt Gray Leather,AW6
DRIVERS SIDE AIRBAG,CF5 ELECTRIC SUNROOF,FE9 FEDERAL EMISSION EQUIPMENT,L67
SUPERCHARGED 3.8L SFI V6,MX0 4 SPEED AUTO W/OVERDRIVE,UP0 AM/FM CASS/CD
PLAYER,
</formatted file>