dbTalk Databases Forums  

bcp for variable input?

comp.databases.sybase comp.databases.sybase


Discuss bcp for variable input? in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Anita Craig
 
Posts: n/a

Default bcp for variable input? - 12-10-2003 , 06:33 PM






I have an output file from another product which has a variable number
of columns, followed by the row-terminator. The first four columns are
always present, the remaining 6 may or may not be present in some number.

I would like to load that data into a Sybase ASE 11.5.1 table which has
10 columns, where the first four columns are the only NOT NULL columns
in the table.

I have tried using bcp -- both with tab-delimited input and with
fixed-length input -- but the load is garbage, since bcp seems to wrap
to the next row to get all 10 columns.

Is there any option I can use to achieve my end, or does anyone have an
alternative suggestion?

Thank you.


Reply With Quote
  #2  
Old   
pjhoust@canada.com
 
Posts: n/a

Default Re: bcp for variable input? - 12-10-2003 , 08:36 PM






You could massage your data to produce 10, tab-delimited fields for each
line of input. If you have Perl, try the following stdin/stdout filter
for each input file:

#!/usr/bin/perl

while(<>) {
chomp;
print join("\t",(@x = split /\t/)), "\t" x (9 - $#x), "\n";
}


Anita Craig wrote:

Quote:
I have an output file from another product which has a variable number
of columns, followed by the row-terminator. The first four columns
are always present, the remaining 6 may or may not be present in some
number.

I would like to load that data into a Sybase ASE 11.5.1 table which
has 10 columns, where the first four columns are the only NOT NULL
columns in the table.

I have tried using bcp -- both with tab-delimited input and with
fixed-length input -- but the load is garbage, since bcp seems to wrap
to the next row to get all 10 columns.

Is there any option I can use to achieve my end, or does anyone have
an alternative suggestion?

Thank you.

--


-----------------------------------------------------------------------
pjhoust (AT) canada (DOT) com
-----------------------------------------------------------------------





Reply With Quote
  #3  
Old   
Anita Craig
 
Posts: n/a

Default Re: bcp for variable input? - 12-15-2003 , 12:57 PM



pjhoust (AT) canada (DOT) com wrote:
Quote:
You could massage your data to produce 10, tab-delimited fields for each
line of input. If you have Perl, try the following stdin/stdout filter
for each input file:

#!/usr/bin/perl

while(<>) {
chomp;
print join("\t",(@x = split /\t/)), "\t" x (9 - $#x), "\n";
}
Well, unfortunately that didn't quite work. I substituted the pipe
character "|" and used input and output files, and I really had 13
(rather than 10) columns so I ran:

open (INFILE, "<Myinput.txt"); # open input file
open (OUTFILE, ">Myoutput.txt"); # open output file

while(<INFILE>){
chomp;
print OUTFILE join ("|", (@x = split /|/)), "|" x (12 - $#x), "\n";
}

Instead of 13 columns delimited by the pipe character, with trailing
ones empty, I ended up with every character of the input line delimited
by the pipe character, including the pipe character delimited by the
pipe character, with no "extra" pipes at the end.

I've not learned Perl, so I don't know what I may have wrong
syntactically -- any other suggestions?

Sample input line:
2003|1|1|AA00

Desired output:
2003|1|1|AA00|||||||||

Output I got:
2|0|0|3|||1|||1|||A|A|0|0



Reply With Quote
  #4  
Old   
Michael Peppler
 
Posts: n/a

Default Re: bcp for variable input? - 12-15-2003 , 04:15 PM



On Mon, 15 Dec 2003 10:57:45 -0800, Anita Craig wrote:

Quote:
pjhoust (AT) canada (DOT) com wrote:
You could massage your data to produce 10, tab-delimited fields for each
line of input. If you have Perl, try the following stdin/stdout filter
for each input file:

#!/usr/bin/perl

while(<>) {
chomp;
print join("\t",(@x = split /\t/)), "\t" x (9 - $#x), "\n";
}
}
Well, unfortunately that didn't quite work. I substituted the pipe
character "|" and used input and output files, and I really had 13 (rather
than 10) columns so I ran:

open (INFILE, "<Myinput.txt"); # open input file open (OUTFILE,
">Myoutput.txt"); # open output file

while(<INFILE>){
chomp;
print OUTFILE join ("|", (@x = split /|/)), "|" x (12 - $#x), "\n";
}
}
Instead of 13 columns delimited by the pipe character, with trailing ones
empty, I ended up with every character of the input line delimited by the
pipe character, including the pipe character delimited by the pipe
character, with no "extra" pipes at the end.
Use split(/\|/) ('|' is a meta character in perl's regular expression
engine.

Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler (AT) peppler (DOT) org http://www.mbay.net/~mpeppler
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.mbay.net/~mpeppler/resume.html



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.