How could I programmatically write results of Show Expression to a file?

Thank you Vitaliy and Shenghui,

I should have been more clear. I want to preserve the formatting in the Cells as well. I am writing these to files and then using this as formatted input for a different purpose (i.e., Creating a dialog with a timed delay )

For example, suppose I have formatted Input and Text like this:


The Show-Cell-Expression forms of these are:

Cell[BoxData[
 RowBox[{
  RowBox[{"f", "[", "x_", "]"}], ":=", 
  "\[IndentingNewLine]", " ", 
  RowBox[{"Module", "[", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"{", "z", "}"}], ",", 
    "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"z", " ", "=", " ", 
      RowBox[{"x", "^", "2"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"x", " ", "z"}]}]}], 
   "\[IndentingNewLine]", "]"}]}]], "Input"]

and

Cell["\<\
1. item 1
2. item 2
3. item 3
4. item 5\
\>", "Section"]

Saving notebook as .m doesn’t preserve the formating. Saving it as .txt preserves the formatting---only if the cells are in their Show-Cell-Expression form.

I could just save it as a .nb and then parse the text of the .nb file as text and extract the cells… but this doesn’t seem very elegant to me.

Shenghui’s method is along the lines of what I want to do programmatically, but the formatting is not preserved:

I think that saving the notebook with everything converted to the Show-Cell-Expression Form is currently the clearest path forward for me, but that also seems to be inelegant.

Thanks, Craig