Skip to content

Instantly share code, notes, and snippets.

View darrinmcdougald's full-sized avatar

darrinmcdougald

View GitHub Profile
@darrinmcdougald
darrinmcdougald / RubySed.rb
Created February 20, 2015 21:12
Emulating sed -i "s/find/replace/g" with ruby
def ChangeOnFile(file, text_to_replace, text_to_put_in_place)
text= File.read file
File.open(file, 'w+'){|f| f << text.gsub(text_to_replace, text_to_put_in_place)}
end
if ARGV.length < 3
abort "\nError: Not enough parameters supplied.\nUSAGE: #{__FILE__} InputFILE, SEARCHSTRING, REPLACESTRING\n"
else
ChangeOnFile(ARGV[0] , ARGV[1] , ARGV[2])
end