UNIX linebreaks in Mac OS

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
danielrr
Posts: 117
Joined: Mon Mar 04, 2013 4:03 pm

UNIX linebreaks in Mac OS

Post by danielrr » Thu Jul 28, 2016 4:48 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7728
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: UNIX linebreaks in Mac OS

Post by FourthWorld » Thu Jul 28, 2016 4:57 pm

How are you writing the file, using the URL syntax or open/write/close?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

danielrr
Posts: 117
Joined: Mon Mar 04, 2013 4:03 pm

Re: UNIX linebreaks in Mac OS

Post by danielrr » Thu Jul 28, 2016 4:58 pm

Thanks. I am using the old open file, write to file, close file method. Is that important?

Klaus
Posts: 11835
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: UNIX linebreaks in Mac OS

Post by Klaus » Thu Jul 28, 2016 4:58 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7728
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: UNIX linebreaks in Mac OS

Post by FourthWorld » Thu Jul 28, 2016 5:24 pm

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
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

danielrr
Posts: 117
Joined: Mon Mar 04, 2013 4:03 pm

Re: UNIX linebreaks in Mac OS

Post by danielrr » Thu Jul 28, 2016 5:50 pm

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7728
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: UNIX linebreaks in Mac OS

Post by FourthWorld » Thu Jul 28, 2016 6:10 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”