Skip to main content

export - LF line break instead of CR+LF when exporting text files on Windows


I want my program to always save a text file with unix-style LF line breaks (even when Mathematica runs on Windows). But the way the built-in Export command works depends on the operating system.


For example the following code:


testFile = "newlinetest.txt";
testStringList = {"abc", "abc"};
Export[testFile, testStringList, "List"];

BinaryReadList[testFile]

Linux or Mac OS gives exactly what I want:



{97, 98, 99, 10, 97, 98, 99}



Windows adds an extra CR symbol:



{97, 98, 99, 13, 10, 97, 98, 99}




Is there a normal way to save text files with unix-style newline on Windows?




Comments