Re: append to a file

*To*: mathgroup at smc.vnet.net*Subject*: [mg46843] Re: append to a file*From*: "Hans Michel" <hansjm at bellsouth.net>*Date*: Wed, 10 Mar 2004 04:57:41 -0500 (EST)*References*: <c2k3ge$qj3$1@smc.vnet.net>*Reply-to*: "Hans Michel" <hansjm at bellsouth.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hi. Do as you asked. But I find the following clumsy code will append to file, as Export will export to streams. I use Range[9] to represent the list you would be evaluating. su[n_]:= Module[{f,filestream}, filestream = OpenAppend["c:\\tempfile.txt"]; f = Range[9]; Do[ {Export[filestream, f, "Table"], Export[filestream, "\n"]}, {i,1,n}]; Close[filestream]; ] su[10] produces 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 However, why not generate your matrix and use the following Export["C:\\tempfile2.txt", Table[Range[9],{10}], "TSV"] the above produces 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 Hans "Francois Coppex" <coppexfrancois at yahoo.fr> wrote in message news:c2k3ge$qj3$1 at smc.vnet.net... > I would like to append to a text file some values in a row, each time the cell is evaluated. > For instance, I'd like to create a text file containing the values: > > a11 a12 a13 a14 a15 a16 > a21 a22 a23 a24 a25 a26 > a31 a32 a33 a34 a35 a36 > a41 a42 a43 a44 a45 a46 > > where aij denotes the j-th value of the i-th run of the evaluation. > The problem is that I wasn't able to figure out how to append the lines to the file. I'm using the > command > > Export["file.txt", {ai1, ai2, ai3, ai4, ai5, ai6}, "Table"]; > > which obviously overvrites the file each time, so that I only get > > ai1 ai2 ai3 ai4 ai5 ai6 > > for all i. Is there a simple way to append the data to the file (goal: include in a DO loop)? > >