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

I have a notebook where evaluation of a certain cell produced hundreds of adjacent output cells using Print. I need to create a list containing all expressions from those output cells as elements, and assign the list to a variable without re-running the evaluation.

Could you suggest a way to automate this process to avoid manually copying all expressions?

share|improve this question
See this post: – Chris Degnen Dec 3 '13 at 19:58
up vote 17 down vote accepted

The following seems to work, however I think it's not general enough:

At a clean nb, enter:

For[i = 0, i < 4, i++, Print[{i, {33, i}}]]
For[i = 0, i < 4, i++, Print[Graphics[Circle[], ImageSize -> 20]]]

Mathematica graphics

And then retrieve the Print[ ] output as:

c = Cases[NotebookRead /@ Cells[GeneratedCell -> True], Cell[___, "Print", ___]];
ToExpression /@ Cases[c, BoxData[__], {2}]

Mathematica graphics

share|improve this answer

How about

Block[{Print = Sow},
  Do[Print[i], {i, 1, 1000}] // Reap
share|improve this answer
In my case, re-running of the evaluation would take longer that manual copying of expressions from existing cells. – Vladimir Reshetnikov Dec 3 '13 at 22:00
Yes sorry, I didn't read "(without re-running the evaluation)". – Chip Hurst Dec 3 '13 at 22:03

Make each result the argument of a pure function; e.g., (Sow[#]; Print[#])&[whatever], with all the functions inside a Reap. That also lets you format the printed output in a way that might be easier for a person to read but more awkward to read back into Mma.

share|improve this answer
Please see the OP's comment under @RiemannZeta answer. The nb has already been calculated. It's too late to change the code. – Dr. belisarius Dec 4 '13 at 11:44

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.