# Problems with txt-export under Macintosh

I exported data form Mathematica to txt-format on my Mac. When opening the txt-file on a Windows-System the file does not appear as on my Mac (see screenshots).

Code: Export["Example.txt", {{"Test1", 1, 2, 3, 4}, {"Test2", 5, 6, 7, 8}}]

Mathematica Documentation Center says "Export uses the line separator convention of the computer system on which Mathematica is being run."

How can I generate a txt-file under Mac OS, so that this file can be read correctly under Windows to?

BTW: I would like to get rid of the braces, quotation marks and commas within the txt-file.

-
Have you tried not using the default OS convention and setting an explicit separator? –  rm -rf Jun 1 '12 at 16:51
You can also not use notepad and use an editor that will read the file properly like notepad++ –  s0rce Jun 1 '12 at 17:01
or try Export["Example.txt", Compress@{{"Test1", 1, 2, 3, 4}, {"Test2", 5, 6, 7, 8}}] and then Uncompress@Import[...] –  acl Jun 1 '12 at 17:05
I suspect this is a \n vs. \r\n issue. To solve this and to get rid of the braces, commas and quotation marks you could try doing something like Export["Example.txt", {{"Test1", 1, 2, 3, 4}, {"Test2", 5, 6, 7, 8}}, "Table", "LineSeparators" -> "\r\n"] –  Heike Jun 1 '12 at 17:42

To eliminate the braces and quotes, you can use the OutputForm of TableForm like this:

testtext = {{"Test1", 1, 2, 3, 4}, {"Test2", 5, 6, 7, 8}}

Export["text.txt", OutputForm[TableForm[testtext]]]


However, this puts a blank line in between rows.

Heike's suggestion in comments also works, and does not put a blank line between rows, but I would suggest adding a CharacterEncoding option if you are sure you will only use the result on a Windows machine.

Export["text.txt", testtext, "Table",
CharacterEncoding -> "WindowsANSI", "LineSeparators" -> "\r\n"]

-

The reason for this is that Windows/DOS and Unix-based systems (like OS X) use different conventions for encoding newlines.

Windows/DOS use a sequence of two character codes: 13 and 10 (13 representing the cursor or print-head returning to the start of the line and 10 representing advancing to the next line). Unix/OS X use a single code: 10. When you use Windows Notepad to open a text file created on a Mac, it will not display it correctly. The little boxes you see represent character code 10, but Notepad never sees a full 13 10 sequence that it can interpret as a newline.

So the problem is not specific to Mathematica. I would suggest that you use a different text editor than Notepad (for example Notepad++), as today nearly all of them support both types of line endings.

Regarding exporting to a table-like format (with no braces), use the Table export format:

Export["Example.txt", {{"Test1", 1, 2, 3, 4}, {"Test2", 5, 6, 7, 8}}, "Table"]

-