From: Daniel Sheppard Date: 2005-10-28T14:48:44+09:00 Subject: Re: Newbie help: File searching and writing output to new file > "file" is a string, the name of a file. It isn't a file handle. > You are not reading from a file. eep. What he said. It seems I'll never learn to test my code before posting... def find_redir File.open("found-redir-lines.txt", "w") do |out| Dir['ex*.log'].each do |in| File.open(in) { |f| f.grep(/redir/) { |line| out.puts(line) } } end end end > ruby -ne"print if /redir/" ex*.log >out.txt Yeah, but that's cheating - you changed the behaviour. What if that found-redir-lines.txt file was important for something else? ruby -ne "i=0;open('found-redir-lines.txt','w'){|f|if /redir/;a=$_;f.puts a;i+=1;puts a if i<2;end}" ex*.log ruby -ne "i=0;open('found-redir-lines.txt','w'){|f|if /redir/;a=$_;f<