From: Dave Thomas Date: 2002-07-06T06:02:05+09:00 Subject: Re: Doesn't quite work...looping question Bob X writes: > It parses, it opens, but it doesn't write to the outFile. So I am > guessing I am not looping through the array properly. > > > #!/usr/bin/ruby -w > > # populate the array > kw = [ "adult", "teen" ] > > # create a file to append data found from the input file > inFile = File.open(ARGV[0], "r") > outFile = File.new(ARGV[1], "w+") > > # search for a word and print the entire line > inFile.each_line { |line| > for kw in line # keywords to search for THis overwrites your kw array with 'line' Try something like (untested) for word in kw if line.include?(word) print line # let the lines print to console outFile.write line # also print to file end end Cheers Dave