From: Yohanes Santoso Date: 2002-03-09T08:13:00+09:00 Subject: Re: Text stuff and appending to a file bobx@linuxmail.org (Bob) writes: > Wyss Clemens wrote in message news:<2121D3CBCBE8D111B2C200805F0DF903F6AFD1@HTKA60MS01NT>... > > lines = File.readlines(ARGV[0]) > > # create a file to append data found from the input file > > logfile = File.open("badwords.txt", "w+") > > # search for a word and print the entire line > > lines.each { | line | > > if /bob/i =~ line > > print line > > logfile.write(line) > > end > > } > Very good! It does indeed do it! Now...since these are very large > files (40-60MB)...is this the best way to read them in? That's quite a large file. Instead of reading everything to memory, how about reading one line at a time: # create a file to append data found from the input file logfile = File.open("badwords.txt", "w+") # search for a word and print the entire line File.open(ARGV[0]) { |file| file.each_line { |line| if /bob/i =~ line print line logfile.write line end } } Also consider using ruby 1.7 which has a much improved IO from what I heard. YS.