From: Wybo Dekker Date: 2005-12-31T20:11:10+09:00 Subject: Re: Newb: Search & Replace On Sat, 31 Dec 2005, Art Gillespie wrote: > #!/usr/bin/env ruby > > VERSION_HEX=ARGV[0] > > File.open("iDrum_prefix.h.tmp", "w") do |ofile| > File.open("iDrum_prefix.h") do |file| > file.each do |line| > if line =~ /^#define kIDComponentVersion\t*(.*)/ > ofile.puts line.sub($1, "#{VERSION_HEX}") > else > ofile.puts line > end > end > end > end > > File.rename("iDrum_prefix.h.tmp", "iDrum_prefix.h") with rio, you can edit a file inplace; this changes all x into y in file z: #!/usr/bin/ruby require 'rubygems' require 'rio' rio('z') < rio('z').read.gsub(/x/,'y') -- Wybo