Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Importing Dos Data into Linux Mathematica?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg14479] Re: Importing Dos Data into Linux Mathematica?
  • From: "P.J. Hinton" <paulh>
  • Date: Fri, 23 Oct 1998 20:58:57 -0400
  • Organization: "Wolfram Research, Inc."
  • References: <70k4lr$enh@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 21 Oct 1998, Charles J. Koehler wrote:

> I am having a problem in trying to import data files that are in
> dos/ascii format.  There is generally a header of 7 rows and 6 col. of
> data. The columns are separated with commas. Each row of the data ends
> with a ^M character.
> 
> I am able to read in the first row of data but nothing more.  I assume I
> need to strip of the ^M that is attached to the last columns of data?
> 
> Does anyone have experience with this?  Your assistance would be
> appreicated.

Here is a Mathematica function that you can use to convert your files
from DOS text to Unix format:

DOSToUnix[filename_String] := 
  Module[{stmpin, stmpout, nextbyte}, stmpin = OpenRead[filename]; 
    stmpout = OpenTemporary[]; 
    While[(nextbyte = Read[stmpin, Byte]) =!= EndOfFile, 
      If[nextbyte != 13, WriteString[stmpout,
FromCharacterCode[nextbyte]]]]; 
    (DeleteFile[#[[2]]]; Apply[CopyFile, #]; DeleteFile[#[[1]]]) & [
      (Close /@ {stmpout, stmpin})]]

For larger files, you will probably want to use shell utility of some
sort to do the job.  Many Unix systems have a utility known as dos2unix
that does the same job as the code above.  If there isn't, you can get
a copy of a similar utility known as d2u from the Sunsite archive
mirrors.  The main site is: 

			ftp://sunsite.unc.edu/

but you should check the mirrors list to find a server closer to you. 
The file is in the directory /pub/linux/utils/text, and the archive is
named d2u-1.3.tar.gz.  The author of the software notes that the source
code was written for Linux, but it should compile on any Unix compiler
that supports ANSI C.

--
P.J. Hinton
Mathematica Programming Group           paulh at wolfram.com Wolfram
Research, Inc.                  http://www.wolfram.com/~paulh/
Disclaimer: Opinions expressed herein are those of the author alone.



  • Prev by Date: Re: I need some help ...
  • Next by Date: Re: ImplicitPlot options (undocumented)
  • Previous by thread: Importing Dos Data into Linux Mathematica?
  • Next by thread: Re: Importing Dos Data into Linux Mathematica?