MathGroup Archive 1997

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

Search the Archive

Re: how to read file line by line?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9188] Re: how to read file line by line?
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Tue, 21 Oct 1997 02:03:01 -0400
  • Organization: University of Western Australia
  • Sender: owner-wri-mathgroup at wolfram.com

charles loboz wrote:

> Assuming input file like that:
>         10 15 30.0
>         10 30 6.0
>         5  30 4.0
>         ...........
> 
> how can I read it, line by line, and discard lines with '15'  as a
> second word?

For the data file

  In[1]:= !!numbers

	10 15 30.0
	10 30 6.0
	5  30 4.0
	10 15 30.0
	10 30 6.0
	5  30 4.0

then, after opening a stream for reading:

  In[2]:= stream = OpenRead["numbers"]; 

you can read it, line by line, and discard lines with '15' as a second
element using

  In[3]:= d = {}; While[(n = Read[stream, Table[Number, {3}]]) =!= 
    EndOfFile, If[n[[2]] != 15, AppendTo[d, n]]]; d

  Out[3]= {{10, 30, 6.}, {5, 30, 4.}, {10, 30, 6.}, {5, 30, 4.}}

Cheers,
	Paul 

____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907       
mailto:paul at physics.uwa.edu.au  AUSTRALIA                            
http://www.pd.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________


  • Prev by Date: Re: Help with findroot
  • Next by Date: mathlm problem on SGI machine
  • Previous by thread: Re: how to read file line by line?
  • Next by thread: Re: Can I read in Mathematica3 (Windows) HDF files