MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Deleting charachter from a text file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68473] Re: Deleting charachter from a text file
  • From: "Giacomo Ciani" <giacomo.ciani at gmail.com>
  • Date: Mon, 7 Aug 2006 01:40:26 -0400 (EDT)
  • References: <ea722g$k1n$1@smc.vnet.net><eaeqc0$54c$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Thanks a lot fot the idea! I would try to implement it as soon as
possible...

Giacomo

Norbert Marxer wrote:
> Hello Giacomo
>
> You don't need to output a correct List expression. You could use
> Newline separated expressions.
>
> You can use either WriteString ...
>
> myStream = OpenWrite["myFile.txt"] ;
> WriteString[myStream, "1"]
> Do[ stepResultArray = x^i;
>     WriteString[myStream,
>       "\n", InputForm@stepResultArray] , {i, 1, 5}
>     ] ;
> Close[myStream];
>
> ... or simply Write ...
>
> myStream = OpenWrite["myFile.txt"] ;
> Write[myStream, 1]
> Do[ stepResultArray = x^i;
>     Write[myStream, stepResultArray] , {i, 1, 5}
>     ] ;
> Close[myStream];
>
> ... and then StringSplit
>
> StringSplit[Import["myFile.txt", "Text"], "\n"]
>
> ... to import the list of your first input expression (which is
> probably not necessary anymore) and the further stepResultArray's into
> Mathematica.
>
> {1, x, x^2, x^3, x^4, x^5}
>
> I hope this helps.
>
> Best Regards
> Norbert Marxer
> www.mec.li
>
>
> Giacomo Ciani wrote:
> > Thanks, but this solution is not feasable for me. I'm running a
> > simulation and one of the reason of writing directly on the file "step
> > by step" the results is not to fill the memory, because I'm genearting
> > a lot of data.
> > Just for curiosity, I'm going to explain the problem in details...
> > actually, what i'm doing is something like:
> >
> > OpenWrite[file]
> > WriteString["{{zeroArray}"]
> > Do[
> > ...calculations...
> > WriteString[file,","]
> > Write[file, stepResultArray]
> > ]
> > WriteString["}"]
> >
> > taht is, I'm writing a list of "resultArrays". But as you can see, my
> > list is not coled by the "}" character till the simulation has ended.
> > What I would like to do is to close the list with the "}" at every
> > step, and the on the next step (after "...calculations...") reopen it,
> > add the new element, and close it again. This way I should be able to
> > import the file in another Mathematica program at any time, even if the
> > simulation is not ended...
> >
> > Bye, and thanks again
> >
> > Giacomo
> >
> > Jens-Peer Kuska wrote:
> > > Hi,
> > >
> > > you must open the file, read the contents in the memory
> > > and save the changed contents.
> > >
> > > Any editor keep the file contents in memory
> > > (atleast partial) and you should do this also.
> > >
> > > Regards
> > >   Jens
> > >
> > > "Giacomo Ciani" <giacomo.ciani at gmail.com> schrieb
> > > im Newsbeitrag news:ea4jva$sck$1 at smc.vnet.net...
> > > | Hello,
> > > |
> > > | I'm using direct access to text files to save
> > > data my program
> > > | generates. So I use a syntax like:
> > > |
> > > | OpenWrite[file];
> > > | WriteString[file,"text"];
> > > | ...
> > > | WriteString[file,"text2"];
> > > | ...
> > > | Ecc...
> > > | Close[file]
> > > |
> > > | I would like to be able to remove some
> > > characters (i.e. the last two
> > > | characters) from the file before writing new
> > > ones (as an example, I
> > > | could need to remove the "xt" character of the
> > > word "text" before
> > > | writing the word "text2"). How can I accomplish
> > > this? I can't find any
> > > | function in the documentation to remove
> > > characters from a file...
> > > |
> > > | Thanks
> > > |
> > > | Giacomo
> > > |


  • Prev by Date: Re: Re: Re: Converting Mathematics slides into PDF
  • Next by Date: Re: critical points of a third order polynomial fit (simplification)
  • Previous by thread: Re: Re: Finding the Number of Pythagorean Triples below a bound
  • Next by thread: Re: Eigensystem[] for higher dimensions?