Export in *nix for use in DOS (was Re: Unix import of a DOS spreadsheet...)

Bruce Easton bruce at stn.com
Wed Sep 8 21:25:21 PDT 2010


  Fully awake now and beg to differ (somewhat--see inline comments).

Bruce

On 9/8/10 12:49 PM, Bruce Easton wrote:
>    (just changing subject for those looking for export - told you i
> wasn't awake yet..)
>
> On 9/8/10 12:29 PM, Bruce Easton wrote:
>>     Without getting nit-pickety about who expressed/quoted something
>> poorly, let me clear up the error in the STN's Developer's Reference.  I
>> believe that the syntax for using 10&13 together as an argument for one
>> of the export flags is invalid.  I believe there was discussion about
>> this here on the forum.  I tried it as the record delimiter long ago and
>> found it to not work.  I've always formatted export files from *nix that
>> are intended for Windows using one of the following methods:
>>
>> 1a.  For a one-time job - I just vi the file and add Ctrl-M's to the
>> ends of the lines using an ed command within vi:
>>
>> g:/$/s/$/[ctrl-M]/g
<-->wrong - g and the colon in wrong order - should  be:
  :g/$/s/[ctrl-M]/g     (the colon from command mode starts the ed command)
>> (where "[ctrl-M]" is obtained by doing a Ctrl-V, then Ctrl-M)
>> (then just save the file)
>>
>> or
>>
>> 1b.  If you're sending the file to the Windows system with ftp, port the
>> file in ascii mode to the Windows system - it should get the Ctrl-M's
>> added to the line endings by whatever you are using to do the ftp.
>>
>> 2. For something that needs to be embedded in a program for regular usage:
<-->Well - if the ftp is automated (as in a script), then again, just 
set the transfer to be ascii mode like 1b above.
>> use sed    (there have been examples of this here not that long ago I
>> think - maybe someone can provide a good example - I have one somewhere
>> - I just can't remember and I haven't had my Sudafed and only half my
>> espresso yet today)
<--begin>
Adding Ctrl-M's using sed in a script can be done with:
sed 's/$/^M/'  [sourcefile] >[modifiedfile]

again, where you get the ^M by holding Ctrl-V, then Ctrl-M.

If using such a script on files that sometimes might already be in DOS 
format,
then you should precede the sed above with one that would remove any 
first, so
you don't wind up with multiple Ctrl-M's per line:
sed 's/^M//g' [sourcefile] >[modifiedfile]

Building one of the commands above within filepro processing can be done
using the code above in a system command and substituting
the ^M with chr("13"), as in:
Then: system "/bin/sed 's/$/"{chr("13"){"/'"<fa<">"{fb
where fa contains the source filename and fb contains the modified filename
<--end>

>> There are some applications that require another ctrl character to be at
>> the end of csv files - I forget which char. - as an end of file marker.
>> So if no one tells you about them, then they can cause a bit of grief
>> until you realize that you have to add/strip that last char as part of a
>> process.
>>
>>
>> Bruce
>>
>>
>> Bruce Easton
>> STN, Inc.
[..]


More information about the Filepro-list mailing list