I need to store long strings from mathematica to a text file.

Unfortunately, mathematica provides long cell entries (input/output) after approx the 70th position with a hidden backslash and a new line character:

/ NL

or hex:

5C 0A

For example, when you write or copy/paste long strings into a text file, the backslash and the newline become visible:

Put[" This ---------------- is ---------------- a ---------------- long ---------------- line", "text.txt"]

The content of text.txt is now 2 separate lines and the backslash is visible:

" This ---------------- is ---------------- a ---------------- long \
---------------- line"

Can this behavior be prevented?

I've tried a lot with:

Text[...], ToString[...], CharacterEncoding -> "...."

I work with Linux and mathematica V13

regards 2stein

  • $\begingroup$ I am trying to understand why the cell outputs have to be copied and pasted manually to a text file. This looks like an XY Problem. $\endgroup$
    – Syed
    Sep 26, 2022 at 9:14

1 Answer 1


Put and Get work with Mathematica expressions. The contents of the file generated with Put is not intended to be read/understood by other programs.

You probably want to use Export (and Import if you need to read the data back into Mathematica).

  • $\begingroup$ Many thanks for your important note In my case, WriteLine[...] works fine too. $\endgroup$
    – 2stein
    Sep 26, 2022 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.