"Ruby Search and Replace Script."

A small standalone script that search through a file doing text substitutions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/usr/bin/env ruby
# Usage $ ruby_search_and_replace.rb file_to_update.txt

def update_file( file_name )
  puts "Updating : #{file_name}"
  ::File.open( file_name, "rb"){ |f| @contents = f.read }

  ## Replace Renamed thing here
  #@contents.gsub!("search","replace")

  ::File.open( file_name, "w" ){ |f| f.write @contents }
end

if $0 == __FILE__
  #If file is called directly execute
  update_file( ::File.absolute_path( ARGV[0] ) )
end

social