Page 1 of 1

UNIX linebreaks in Mac OS

Posted: Thu Jul 28, 2016 4:48 pm
by danielrr
Hi everyone!

How can I write to a file im MacOs with unix line-breaks? I see that there's no use in using

Code: Select all

      replace numToChar(13) with numToChar(10) in container 
or
replace numToChar(13) with linefeed in container
before exporting it to a file, because LC will translate it into mac linebreaks. I need unix linebreaks cause my database managers only like import files with unix linebreaks.

best,

Daniel

Re: UNIX linebreaks in Mac OS

Posted: Thu Jul 28, 2016 4:57 pm
by FourthWorld
How are you writing the file, using the URL syntax or open/write/close?

Re: UNIX linebreaks in Mac OS

Posted: Thu Jul 28, 2016 4:58 pm
by danielrr
Thanks. I am using the old open file, write to file, close file method. Is that important?

Re: UNIX linebreaks in Mac OS

Posted: Thu Jul 28, 2016 4:58 pm
by Klaus
Hi Daniel,

export your text to BINFILE (instead of FILE) , that will preserve your modifed line breaks!
...
put my_text_with_unix_linebreaks into url("BINFILE:" & wherever & "/unixlinebreaks.txt"))
...

Best

Klaus

Re: UNIX linebreaks in Mac OS

Posted: Thu Jul 28, 2016 5:24 pm
by FourthWorld
Like Klaus said. With the open/write/close method, the difference between text writes (which alter line-endings to be native to the current host platform) and binary (which leaves data in its LC-native format, where LC happens to use Unix line-endings), this is handled in the open command, e.g.:

Code: Select all

open file tFile for binary write

Re: UNIX linebreaks in Mac OS

Posted: Thu Jul 28, 2016 5:50 pm
by danielrr
Thanks Klaus, FourthWorld; you both made my day. Both ways work like a charm. Alas, for very large files (I mean a monster of 700MB) the option of opening in binary and use the read/write is much faster that using the url binfile option, so I used the former. Thanks again.

Re: UNIX linebreaks in Mac OS

Posted: Thu Jul 28, 2016 6:10 pm
by FourthWorld
danielrr wrote:...for very large files (I mean a monster of 700MB) the option of opening in binary and use the read/write is much faster that using the url binfile option...
With either the URL or open method, binary is also faster than text mode, since it avoids the overhead of tracking down and replacing line endings. Texyt mode is useful for trivial reads and writes where platform-specific line endings may be a nice convenience for the end-user. But as a general rule I tend to use binary mode to get optimal performance and have assurance I'm working on unaltered data.