Re: Importing Dos Data into Linux Mathematica?
- To: mathgroup at smc.vnet.net
- Subject: [mg14466] Re: Importing Dos Data into Linux Mathematica?
- From: Rolf Mertig <rolf at mertig.com>
- Date: Fri, 23 Oct 1998 20:58:45 -0400
- Organization: Mertig Research & Consulting
- References: <70k4lr$enh@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
It looks like that ^M in Mathematica is represented by \r. Thus, the
following is one possibility to get rid of ^M's completely from within
Mathematica : (use as: DosToUnix["thedosfiletobeconverted.m"] ):
Options[DosToUnix]={CopyFile->False};
DosToUnix[file_String, opts___Rule]:=Block[{t},
t=ReadList[file,String];
t=Map[If[StringLength[#]===0,#,If[StringTake[#,-1]==="\r",StringDrop[#,-1],#]]&,t];
If[CopyFile/.{opts}/.Options[DosToUnix],CopyFile[file, file<>"old"]];
DeleteFile[file];
Do[WriteString[file,t[[i]],"\n"],{i,Length[t]}]; Close[file]];
Charles J. Koehler wrote:
>
> Hello,
>
> 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.
>
> Sincerely,
>
> Charles J. Koehler
--
Dr. Rolf Mertig
Mertig Research & Consulting
Mathematica training and programming Development and distribution of
FeynCalc Amsterdam, The Netherlands
http://www.mertig.com