Mathematica 9 is now available
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: [mg34729] Re: eliminate some characters inside a file
  • From: "John Jowett" <John.Jowett at cern.ch>
  • Date: Tue, 4 Jun 2002 03:41:38 -0400 (EDT)
  • References: <adca4e$1lp$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hello, here's a simple method.  If you copy the small Notebook expression
below and paste it into the Front End, it will take you through the steps:

(* Beginning of notebook expression*)
Notebook[{
Cell["Choose directory where the files are:", "Text"],

Cell[BoxData[
    \(SetDirectory["\<C:\\Documents and
Settings\\jjowett\\Desktop\\fixdata\\\
\>"]\)], "Input"],

Cell["Get a list of the files", "Text"],

Cell[BoxData[
    \(filesToFix = FileNames["\<*.txt\>"]\)], "Input"],

Cell["Pick one just to show how", "Text"],

Cell[BoxData[
    \(testFile = First[filesToFix]\)], "Input"],

Cell[BoxData[
    \(Import[testFile, "\<Text\>"]\)], "Input"],

Cell[BoxData[
    \(StringReplace[
      Import[testFile, "\<Text\>"], {"\<\"\>" -> "\<\>", "\<,\>" -> "\<
\>"}]\
\)], "Input"],

Cell[BoxData[
    \(Export["\<fixed\>" <> testFile,
      StringReplace[
        Import[testFile, "\<Text\>"], {"\<\"\>" -> "\<\>", "\<,\>" -> "\< \
\>"}], "\<Text\>"]\)], "Input"],

Cell["\<\
Wrap up the method as a pure function and Map it over all the files\
\>", "Text"],

Cell[BoxData[
    \(\(Export["\<fixed\>" <> #,
          StringReplace[
            Import[#, "\<Text\>"], {"\<\"\>" -> "\<\>", "\<,\>" -> "\<
\>"}], \
"\<Text\>"] &\) /@ filesToFix\)], "Input"]
}
]
(* end of notebook expression*)

Hope this helps,
John Jowett
My home page:    http://cern.ch/jowett/



"A.M." <moreno at alumnos.uva.es> wrote in message
news:adca4e$1lp$1 at smc.vnet.net...
> 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: RE: Re: Is it possible to access internal variables?
  • Next by Date: RE: Help with Select[]
  • Previous by thread: Re: eliminate some characters inside a file
  • Next by thread: repeated entries in File>Palettes menu (again)