0
$\begingroup$

I used PutAppend to write away a some results. It turns out that Mathematica has inserted annoying line breaks. This is discussed in Why there are line breaks when PutAppend a string to file? and it offers some ways to avoid this from happening in the future. But how do I clean up the files that were already written away with the default PutAppend? Note there are also line breaks that are supposed to be there. Is there a good way to recognized the line breaks that Mathematica decided to add and remove them?


Each separate result was supposed to be printed on a newline

result1
result2

but now there are additional line breaks breaking up the results. I had thought this would make the files nice to read with ReadList. Now it turns out it is terrible due to the unintended line breaks.

$\endgroup$
  • $\begingroup$ StringReplace[Import[file], "\"\n\"" -> "\"\""]? $\endgroup$ – kglr Nov 26 '18 at 23:03
  • $\begingroup$ @kglr that replacement leaves the result of Import[file] unchanged. (StringReplace[Import[file], "\"\n\"" -> "\"\""]===Import[file] gives True.) $\endgroup$ – Kvothe Nov 27 '18 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.