Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*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 2002

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

Search the Archive

RE: eliminate some characters inside a file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34726] RE: [mg34716] eliminate some characters inside a file
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Mon, 3 Jun 2002 01:46:49 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

My solution seems unnecessarily complicated, but here goes...

I'll convert all *.txt files in an input directory into new files in an
output directory.

inputDirectory = "Moreno";
outputDirectory = "Moreno2";
Off[CreateDirectory::"ioerr"];
CreateDirectory[outputDirectory];
On[CreateDirectory::"ioerr"];

This reads one input file and writes the corresponding output file:

fixFile[input_String, output_String] :=
  Module[{x, in, out},
    Close /@ Streams[output];
    out = OpenWrite[output, FormatType -> OutputForm];
    Close /@ Streams[input];
    in = OpenRead[input];
    While[(x = Read[in, String]) =!= EndOfFile,
      Write[out, StringJoin[DeleteCases[Characters[x], "\""] /. "," -> "
"]]
      ];
    Close /@ {in, out}
    ]

Apply fixFile to all files in the input directory, placing identically
named files in the output directory:

fixFile[#, 
      ToFileName[outputDirectory, 
        StringDrop[#, StringLength[DirectoryName[#]]]]] & /@ 
  FileNames["*.txt", inputDirectory]

Bobby Treat

-----Original Message-----
From: A.M. [mailto:moreno at alumnos.uva.es] 
To: mathgroup at smc.vnet.net
Subject: [mg34726] [mg34716] eliminate some characters inside a file

Hi everybody,

this is my question: I´ve got a large numbers o files with the next
appearance:

"12,56,12,14"
"13,56,25,36"
"14,58,465,7"
    .
    .
    .

and I need Mathemathica to eliminate " " and changes , by blank space to
obtain the next:
12 56 12 14
13 56 25 36
14 58 465 7
    .
    .
    .
If anybody can help me I would be very pleased

thanks






  • Prev by Date: Re: repeated entries in File>Palettes menu (again)
  • Next by Date: RE: Package problem
  • Previous by thread: RE: eliminate some characters inside a file
  • Next by thread: Re: eliminate some characters inside a file