Replace string in a file
def stringReplace(searchString, replaceString, fileName)
aFile = File.open(fileName, "r")
aString = aFile.read
aFile.close
aString.gsub!(searchString, replaceString)
File.open(fileName, "w") { |file| file << aString }
end
stringReplace(*ARGV)
Related examples in the same category