steve_rubytalk wrote:
> William James wrote:
>> ruby -i.bak -ne 'print if $_ !~ /foo/' stuff.txt
> Coo... that's a new one to me... very nifty.
> 
> Unfortunately, I mislead you... I want to transform a file from within a
> cgi script... which means I need to use standard out to generate other
> feedback to the user.  Is a similar facility available within a ruby
> program without executing a new ruby process?

File.new( "stuff.txt" ) do | f |
  f.each do |line|
    print unless line =~ /foo/
  end
end

Or if you needed to rewrite it to a different file

File.new( "stuff.txt" ) do | in |
  File.new( "newstuff.txt", "w" ) do |out|
    in.each { | line | out.print line unless line =~ /foo/ }
  end
end

-- 
Posted via http://www.ruby-forum.com/.