MathGroup Archive 2005

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

Search the Archive

Importing tab-delimited data files?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62604] Importing tab-delimited data files?
  • From: AES <siegman at stanford.edu>
  • Date: Tue, 29 Nov 2005 04:45:17 -0500 (EST)
  • Organization: Stanford University
  • Sender: owner-wri-mathgroup at wolfram.com

I create a text file "filedata" with the following content using a text 
editor, with tabs between each number or string (5 tabs per line), and 
no content -- not even a space, just successive adjacent tabs -- in the 
empty slots.

(The columns should line up if your reader uses monospaced type.)

11   aaa  22   bbb  33   ccc
              22   bbb  33   ccc
                            33   ccc

Opening Mathematica and using  !!filedata  reproduces exactly same thing:
 
11   aaa  22   bbb  33   ccc
              22   bbb  33   ccc
                            33   ccc

Trying to follow this with   

   fileDataAsViewed = !!fildata   

or   

   fileDataAsViewed = %

doesn't work, however.

Using the Mathematica expression

   Import["datafile", "Table",   
      ConversionOptions->{"TableSeparators"->{{"\r","\n"},{"\t"}}}]

gives:

11   aaa  22   bbb  33   ccc
22   bbb  33   ccc
33   ccc

Recreating the text file with a space between the tabs in the empty 
slots and applying the same  Import[ ]  expression, however, gives the 
"right" answer:

11   aaa  22   bbb  33   ccc
              22   bbb  33   ccc
                            33   ccc

I suppose this is not exactly unexpected.  The problem is, the app that 
creates the (much larger) tab-delimited filedata text file I really want 
to load into a Mathematica Table creates numerous blank cells, i.e. 
adjacent and unspaced tabs.  I guess I'll just have to go at it with a 
smart text editor and separate adjacent tabs before trying to load it.


  • Prev by Date: Re: MatrixForm
  • Next by Date: Re: Re: Package development
  • Previous by thread: Re: Re: function of a function
  • Next by thread: Table Formatting