RE: manipulating data files
Posted in 2000
Try:
#!/usr/local/bin/perl
while (<>) {
chop;
$a = substr($_,0,22);
$b = substr($_,22,12);
$c = substr($_,34);
print "$a|$b|$c|\\n";
}
This leaves in the trailing spaces, but that doesn't bother a load file.
> -----Original Message-----
> From: triggerfish2001@hotmail.com [SMTP:triggerfish2001@hotmail.com]
> Sent: Wednesday, October 18, 2000 5:23 PM
> To: informix-list@iiug.org
> Subject: manipulating data files
>
> Hi,
>
> I have just basic knowledge of perl. The task I need to accomplish is as
> follows:
>
> source file needs to be converted to target file.
>
> source file will be a fixed column length ASCII file of data.
>
> target file will be a PIPE ('|') seperated ASCII file of data.
>
> For eg:-
> source file will be as follows:
>
> John Smith 745-678-089011-10-1955
> Robert IhaveAlongName345-567-453219-04-1967
>
> Here the first 22 char is fixed length for name
> Starting from 23rd char next 12 char is for SSN
> Starting from 35th char next 10 char is for DOB.
>
> Now this needs to be changed to
> John Smith|745-678-0890|11-10-1955|
> Robert IhaveAlongName|345-567-4532|19-04-1967|
>
> The reason for this is that informix dbload or high performance loader
> needs
> a field delimiter.
>
> How can this be achieved in perl.
>
> thanks.