From: Ken Bloom Date: 2008-10-28T06:40:27+09:00 Subject: Re: file manipulation On Mon, 27 Oct 2008 13:35:28 -0700, Vandana wrote: > Hi All, > > I have one more question with file manipulation. > > Suppose I have the following structure in a file : --------------------- > Instance J1 ( > net n1() > net n2 () > net n3() > ) > Instance J2 ( > net n1() > net n2() > net n3() > ) > Instance J3 ( > net n1() > net n2() > net n3() > ) > ----------------------- > As an example, I want to read J3/net n3. (the files are huge ....in GB) > I can grep for n3 but it will return 3 instances of n3. > > How can I ensure that Im reading n3 values that belong to instance J3? > > Thank you for your time. I really appreciate your help. > > Thanks > Vandana. If your file was in XML, you could use REXML::Parsers::SAX2Parser (or some other SAX parser) to create a solution that turns on an @inInstanceJ3 variable when it encounters the right piece of data, turns off @inInstanceJ3 when it encounters the matching close tag, and records n3's only when @inInstanceJK3 is true. For your format, I suggest you find a parser generator that lets you create actions for different grammar elements, to implement a similar solution. -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/