"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<<a;i+=1;puts a if i<2;end}" ex*.log
ruby -ne "i=0;open('found-redir-lines.txt','w'){|f|if
/redir/;f<<$_;print if(i+=1)<2;end}" ex*.log
ruby -ne "i=0;open('found-redir-lines.txt','w'){|f|f<<$_&&(print
if(i+=1)<2)if/redir/}" ex*.log
And I think that's about as much golf as I'm capable of playing.
···
#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################