From: ts Date: 2002-03-10T21:06:31+09:00 Subject: Re: Text stuff and appending to a file >>>>> "B" == Bob writes: B> I would like the lines that it finds with "bob" to print to the B> console and append to the logfile. Well, you have also the stupid way to do it moulon% cat b.rb #!/usr/bin/ruby class << $defout attr_reader :aux def aux=(a) @aux.close if @aux @aux = a end def write(s) super @aux.write(s) if @aux end end input = File.open(ARGV[0], "r") $defout.aux = File.new("badwords.txt", "a") input.each do |line| print "first : #{line}" if /bob/i =~ line end $defout.aux = nil input.rewind input.each do |line| print "second : #{line}" if /bob/i =~ line end moulon% moulon% cat a bob1 aaaa bob2 moulon% moulon% b.rb a first : bob1 first : bob2 second : bob1 second : bob2 moulon% moulon% cat badwords.txt first : bob1 first : bob2 moulon% Guy Decoux