MathGroup Archive 2005

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

Search the Archive

Re: Write/WriteString -- writing delimited txt to a stream?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57980] Re: Write/WriteString -- writing delimited txt to a stream?
  • From: "Stefan Linnik" <- at mk-nntp-1.news.uk.worldonline.com>
  • Date: Wed, 15 Jun 2005 05:58:13 -0400 (EDT)
  • References: <d8jm0b$t23$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

A simple way might be something like:

(* init file.txt *)
strm= OpenAppend["c:\\file.txt"]
Do[
    ...
    dataChunk= { {100, 1.5, -10}, {200, 3.2, 10}, ...etc};
    Export[strm, dataChunk, "CSV"]
    ...
    ]

Stefan Linnik
~~~~~~~~


"Lee Newman" <leenewm at umich.edu> wrote in message 
news:d8jm0b$t23$1 at smc.vnet.net...
> Hello,
>
> Situation:
> -  I am reading data in from a stream (the file is too big to import)
> and processing it chunk by chunk.
> -  The proesssed data looks something like  data = {{100, 1.5, -10},
> {200,3.2, 10},...etc}
> - I have opened an output stream to write the data using   s =
> OpenWrite[file, FormatType -> OutPutForm];
> - I want to write the data in tab or comma separated format with one row
> per line.
>
> Problem:
> - No matter what I've tried, I always get either
>    (i) output with rows enclosed in brackets, or
>   (ii)  delimited text output, but with Mathematica automatically adding a 
> line
> break if a line exceeds what seems to be the default width for output 
> format
> -  I've tried using Write and WriteString -- nothing seems to work.
> - I also tried generating an exact string for each line using a function
> that inserts tabs between list items and adds a newline at the end of
> the list.
>
> ExpressionToTSV[list_] := Module[{temp},
>       temp = ToString@Rest@(ToString /@ Flatten@({"\t", #} & /@ list));
>       StringReplace[temp, {"{" -> "", "}" -> "", ", " -> ""}];
>       StringInsert[temp, "\n", -1]
>       ];
>
>
> There must be a simple solution -- does anyone know how to do this?
>
> Any help would be greatly appreciated,
> Lee
> 



  • Prev by Date: Re: Re: Peculiar behaviour of Mathematica code
  • Next by Date: Re: make a set of conditions without the parameters
  • Previous by thread: Re: Write/WriteString -- writing delimited txt to a stream?
  • Next by thread: make a set of conditions without the parameters