MathGroup Archive 2006

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

Search the Archive

Input, output troubles me ...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70010] Input, output troubles me ...
  • From: "luigirmailbox-mathematica at yahoo.it" <luigirmailbox-mathematica at yahoo.it>
  • Date: Sat, 30 Sep 2006 05:12:38 -0400 (EDT)
  • Reply-to: luigirmailbox-mathematica at yahoo.it

Dear Friends

I have been using Mathematica for text file processing for a long time.
I found it's a valuable tool for text complex manipulations.

The strategy I was used to apply is well condensed in this childish
example:

---------------------------------
(*loading the content*)
dummy = Import["c:\\myDir\\inputFile.txt", "Lines"];
(*processing it*)
dummy = Select[dummy, (# != "a") &];
(*exporting it*)
Export["c:\\myDir\\outpuFile.txt", dummy, "Lines"];
---------------------------------

Now I have to face huge file (up to 5,6 Gb sized) and the previous
technique mostly crashes my systems.

I would like to process a single line, rather than the whole load,
doing something similar what a classical programmig language does:

---------------------------------
Open "c:\\myDir\\inputFile.txt" for Input As #1
Open "c:\\myDir\\outputFile.txt" for Input As #2

Do While Not Eof(#1)
   Line Input #1, dummy$
   If dummy$ <> "a" Then Print #1, dummy$
Loop

Close #1
Close #2
---------------------------------

I tried this (and many others!) trick:

---------------------------------
stream1 = OpenRead["c:\\myDir\\inputFile.txt"];
stream2 = OpenWrite["c:\\myDir\\outputFile.txt"];
While[
   dummy != EndOfFile,
   dummy = Read[stream1, "String"];
   If[dummy != "a", Write[stream2, dummy]];
]
Close[stream1];
Close[stream2];
---------------------------------

But it doesn't work: when inputFile is

a
b
c
d

outputFile is void, not

b
c
d

as expected.

Plaese can someone help me?

Thanks for your attention.
Goobye.


  • Prev by Date: Re: Vector operations,
  • Next by Date: RE: How to make a progress bar?
  • Previous by thread: HoldPattern question
  • Next by thread: Smarter way to calculate middle-right terms of continued fraction partial sums