MathGroup Archive 2005

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57944] Write/WriteString -- writing delimited txt to a stream?
  • From: Lee Newman <leenewm at umich.edu>
  • Date: Mon, 13 Jun 2005 05:51:08 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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: Beginner's Question on I/O Files for Raw Numerical Data
  • Next by Date: Re: Beginner's Question on I/O Files for Raw Numerical Data
  • Previous by thread: Re: Text Manipulation
  • Next by thread: Re: Write/WriteString -- writing delimited txt to a stream?