Hi,

"Jason" <jasowong / my-deja.com> wrote in message
news:95iage$8n$1 / nnrp1.deja.com...
> Hi All,
>
> Below is a directory wide (or file wide, depending on your preference)
> search and replace method, written in Ruby.  Just so I know I'm on the
> right track, is that the quickest way to write the application (ie, is
> there a shortcut around creating an object named aFile, and then
> writing to the file?
>
>
>  def sr(searchString, replaceString, fileName)
>  if File.stat(fileName).file?
>      aFile =  File.open(fileName, "r").read.gsub(searchString,
> replaceString)
>      File.open(fileName, "w").print(aFile)
>  end
> end
> (ARGV.length - 2).times { |i| sr(ARGV[0], ARGV[1], ARGV[2+i])}
>

How about this?

#!/usr/local/bin/ruby -pi
BEGIN {
  $searchString = ARGV.shift
  $replaceString = ARGV.shift
}
gsub($searchString,$replaceString)

> Jason
>