From: Robert Klemme Date: 2007-04-04T02:00:22+09:00 Subject: Re: search a file and replace text On 03.04.2007 18:56, phil.swenson@gmail.com wrote: > well I *THOUGHT* I knew how to do it, here's my first crack at it: > > file_name = base_config_path + '/Caching/tangosol- > coherence.xml' > File.open(file_name, File::RDWR).each{ |line| > if line.gsub!(/30890/, port.to_s) > puts "tangosol port overridden with %d" % port > break > end > } > > > The gsub doesn't modify the line, guess it just modifies the string. Exactly. > How do I actually modify the file itself? Read it, modify it, write it. Or use ruby -pi.bak ... robert