Bcp command error in uploading data to Sybase

Hi All,

I had an issue in executing bcp command to connect to Sybase from Unix script for uploading the data from file to table.

I have a file called vrs_temp.txt (with two columns):

22055;20181001
21088;20181001
93840;20181001
30990;20181001
50990;20181001
50950;20181001

Created a table using isql command (with three columns - the third one should be null in database). Then used bcp command to insert the data:

1st Error:

bcp $db..table_name in vrs_temp.txt -U$Login -PPASSWD -S$DBName -c -t\\;

by using the above command I have got the below error and it doesn't uploaded the date into table.

Starting copy...
Unexpected EOF encountered in BCP data-file.
bcp copy in failed

2nd Error:

bcp $db..table_name in vrs_temp.txt -U$DBLogin -PPASSWD -S$DBName -c -t\;

The error I got was :

Starting copy...
CSLIB Message:  - L0/O0/S0/N24/1/0:
cs_convert: cslib user api layer: common library error: The conversion/operation was stopped due to a syntax error in the source field.
CSLIB Message:  - L0/O0/S0/N36/1/0:
cs_convert: cslib user api layer: common library error: The result is truncated because the conversion/operation resulted in overflow.

Could you please check and let me know the problem in the command.

Thanks.

Just an idea. Try changing in the txt file the EOL character to CRLF or vice versa. (some version of dos2ux or ux2dos).

Sorry, I didn't understand could you breif the idea you are proposing.

Thanks

UNIX (and similar OSes linke Linux) and DOS (and its successors linke Windows) have different ways of ending lines in a text file. Somehow software has to know that e.g. in:

first line
second line

after the "e" of "first line" this line ends and a new line begins. Otherwise it would all be one line. DOS/Windows does this with a 2-character sequence (in hexadecimal notation: 0x0D 0x0A, a "carriage return" character, followed by a "linefeed" character), whereas UNIX does it with a 1-character code (a "newline" character). dos2unix and unix2dos are two programs which convert files from one format to the other, according to their name. rdtx1 suggested you should use one of them because maybe the file you have is in the wrong format for your system (DOS version on a UNIX system or vice versa).

I hope this helps.

bakunin

Thank you. Actually the problem is with the file format at end of each line. So, I have added a semicolon delimiter and tried accessing the bcp command to load the data into Sybase.

awk -v d=`date +%Y%d%d";"` -FS="," -vOFS=";" '{$2=d; print $1,$2}' temp.txt > new_file.txt

22055;20181004;
21088;20181004;
93840;20181004;
30990;20181004;
50990;20181004;
50950;20181004;

bcp db..table_name in new_file.txt -U$Login -PPASSWD -S$DBName -c -t";"

Copied 11 rows to database