Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  PutAppend[Table[i, {RandomInteger[100]}], "./file.m"],
  {i, 100}

I'd like each inner list to always appear on the same line, but not automatically wrapped at 68th character. How to achieve that? I wonder where and how the PageWidth option should be set for the InputStream used by the PutAppend.

#!/usr/bin/env bash

sed -e '
    /.* $/ {
        /\n .*$/ {
            s/\(.*\) \n \(.*\)/\1 \2/
' $1

will fix the broken lines.

share|improve this question
Strongly related: (9977). – Alexey Popkov Jul 18 '15 at 9:32
up vote 2 down vote accepted

I believe you should use streams:

stream = OpenWrite["wraptest.m", PageWidth -> Infinity];

Do[PutAppend[Table[i, {RandomInteger[100]}], stream], {i, 100}]

You can also use Write in place of PutAppend:

 Do[stream ~Write~ Table[i, {RandomInteger[100]}], {i, 100}]

Be sure to Close your stream when you are done:

share|improve this answer
It's well acceptable. The documentation doesn't say the second argument can be a stream expression. – qazwsx Apr 24 '12 at 4:26
If I have a file written in my original way and have some long lines wrapped, how to amend it so each line has exactly one expression (List in this case) without rewriting the large file? – qazwsx Apr 24 '12 at 4:27
@Problemania I didn't check the documentation before posting; I thought it was in there but it seems not. As for fixing your existing file my first inclination is to read in the data and write it to a new file. If memory usage is your concern you can do it line by line with Read and Write. – Mr.Wizard Apr 24 '12 at 4:33
Writing those files took hours. To fix the line breaks, I would have to basically rewrite them? It doesn't have to use Mathematica if there is better way to do it. It seems the broken long line always has the second and additional lines start with white spaces. Maybe that could be exploited? – qazwsx Apr 24 '12 at 4:44
I find a way to fix the long lines with sed (see in OP). – qazwsx Apr 24 '12 at 5:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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