From: Ken Bloom Date: 2009-10-12T11:08:42+09:00 Subject: Re: find a print out a line On Fri, 09 Oct 2009 21:35:11 +0900, R端diger Bahns wrote: > Collin Moore schrieb: >> Hi >> I am slowly learning Ruby and working on a solution. I have huge text >> files with tons of garbage and I want to extract just specific lines >> including the word 'TestPhase'. >> >> Looking for simple solutions, just struggling with the problem. >> >> Thanks in advance for advice and help. > > To reduce the array File.readlines returns to only the lines that > contain 'TestPhase' use > > File.readlines('file.txt').grep /TestPhase/ If you don't want to store the whole file in memory while you're grepping it, then the following will work better. open('jasmin.txt'){|f| f.each_line.grep /TestPhrase/} -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/