Subject Re: separator for CSV file to be imported into dBase
From Gaetano <gaetanodd@hotmail.com>
Date Thu, 24 Sep 2020 07:29:24 +1000
Newsgroups dbase.getting-started
Attachment(s) input.txtoutput.csv


There was a typo in Akshat's code ";" = Chr(59), I added the double
quotes in the same stuff operation. Try this (mind the wordwrap for the
line starting with "stuff", it belongs to the previous line).

I have attached your sample input and the output produced by the below code.

set safety off
fout = new file()
in = new file()
in_file = getfile("input.csv")
   if not empty(in_file)
     fin.open(in_file)
     fout.create("output.csv")
     do while not fin.eof()
        chr_str = fin.readln()
          do while at(chr(59),chr_str) >0
             chr_str = stuff(chr_str,at(chr(59),chr_str),1,'","')                                        
         enddo
        chr_str='"'+chr_str+'"'
         fout.writeln(chr_str)
         enddo
fin.close()
fout.close()
endif

I am not sure I understand your comment about 500 successive fields,
surely no table has 500 fields... can you clarify? (je parle francais si
ca peut faciliter les choses, meme si pour avoir des reponses des vrais
experts, l'anglais est preferable)

if this is too slow, perhaps you need to consider using a regular
expression, that is blazing fast on large volumes.

Bonne chance.

Cheers,
Gaetano.

On 24/09/2020 01:59, Jean R. from Paris wrote:
> Mervyn Bick Wrote:
>
>> On 2020/09/23 15:54, Jean R. from Paris wrote:
>>> Hi
>>>
>>> I have some large CSV files to get imported into dBase.
>>> the fields separators being ";" dBase does not like that
>>> Since I cannot change the fields separators. How could i go around the limitation and find a way to import the CSV file into dBase
>>
>> Importdata.wfm in the dUFLP can handle files where a separator other
>> than a comma has been used.  This basically requires a fair bit of input
>> from the user so it is OK for an occasional file but it becomes a
>> nuisance if you have many files to deal with.
>>
>> The alternative is, as Akshat has said, to write code to do this your self.
>>
>> If you give more details we may be able to help.
>>
>> What version of dBASE are you using?
>>
>> Are character fields in the .csv file delimited with single or double
>> quotes.  (The only need to be delimited if commas are included in the
>> text but many programs add delimiters even if they are not needed.)
>>
>> If there are dates in the .csv file which will be imported into date
>> fields in the dBASE table what format are they in?
>>
>> Mervyn.
>
> Thank you Mervyn
>
> I am using the latest dBase 2019-1
>
> At this moment dates are not a concern because I am mostly dealing with names and numerical values which can be kg or parices with "," as a separator.
>
> fields are separated by the ";" only without double quotes which I use here for the sake Clarity only.
>
> as an example one line of the CSV file can be as follows:
>
> 2014;INTOS;INTOS;S&P;CANDE;SP 75 - S25;SP 75;25;16,40;USD;IT;ETE;0;0;0;0;0;0;50;0;100;0;25;0;175;CC
> the end of the line will be "CR LF" standing for carriage return - line feed
>
> another line can look like :
>
> 2014;CHEL;CHEL COMPIGE;NOF-OC;WBRID;DE S-753 - F200;DE S 753;200;21,95;EUR;FR;CRA;0;0;0;0;0;0;600;0;600;0;800;0;2000;CC
> the end of the line will be "CR LF" Standing for carriage return - line feed
>
> This file can be thousands of lines
>
> Other similar files to be processed can be 500 or more successive fields which DBIMPORT cannot handle either.
>
> Thank you for your thoughts
>
> Jean R. from Paris
>
>
>
>
>
>
>




2014;CHEL;CHEL COMPIGE;NOF-OC;WBRID;DE S-753 - F200;DE S 753;200;21,95;EUR;FR;CRA;0;0;0;0;0;0;600;0;600;0;800;0;2000;CC
2014;INTOS;INTOS;S&P;CANDE;SP 75 - S25;SP 75;25;16,40;USD;IT;ETE;0;0;0;0;0;0;50;0;100;0;25;0;175;CC