Re: HOW in the HECK can we import comma quote delimted ASCII !!!????
Posted in 1995
Topics: Server Administration
root@TeamInfinity.com (root) writes:
>I cannot find out how to import comma quote delimited text into Informix
>if my life depended on it. We looked at dbload and got it to work ONLY
>after converting our comma quote delimited ascii text file to single
>character limited ascii text with much labor. comma quote delimited
>ascii is very much a standard data format. There MUST be a way to import
>comma quote delimited text into informix, but I sure could not find it !
>See we are trying to import dbaseIII and paradox files into informix by
>first converting them to the WORLD STANDARD of comma quote delimited ascii
>text, but informix's dbload seems to only allow importation of ascii text
>that is delimited with a SINGLE character. Please tell us this is NOT so.
> Thanks in advance,
> root@TeamInfinity.com (Eric Sean Webber)
For those of you with PERL, this script takes a file delimited "," and
changes it to the delimiter of your choice:
#!/usr/bin/perl
$delimiter = '|' ;
while (<>) {
chop ;
#change "," delimitation to $delimiter
$str = 0 ;
undef $line ;
while ( $str < length($_) ) { #go through the line
$char = substr($_,$str,1) ; # get the current character @ offset $str
if ( $char eq $delimiter ) {
print "\\n", $_, "\\n" ;
die "ERROR: Delimiter found in file\\n" ;
}
if ( $char eq '"' ) { # if a quote mark
$quote = $quote ? 0 : 1 ; # toggle quote
}
if ( ! $quote && $char eq ',' ) { # if not in quoted material
$line .= $delimiter ; # and char is comma, set delimiter
} else { # else put the char back
$line .= $char if ( $char ne '"' ) ;
}
$str++ ; # increment offset
}
# another problem: some programs chop ASCII output to 80 chars
# so we put the lines back together
if ( substr($line,-1,1) eq '+' ) {
chop $line ;
$bigline .= $line ;
} else {
$bigline .= $line ;
print $bigline, "$delimiter\\n" ;
undef $bigline ;
}
}