Last active
December 16, 2015 17:39
-
-
Save eman41/5471678 to your computer and use it in GitHub Desktop.
A ruby snippet found on SO for doing a find and replace in a text file. Slightly modified for a recent use case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired this question/answer (up-vote him!): | |
# http://stackoverflow.com/a/1274631/1598965 | |
file_names = ['foo.txt', 'bar.txt'] | |
file_names.each do |file_name| | |
text = File.read(file_name).gsub(/search_regexp/, "replace string") | |
# This will overwrite the existing file with the above gsub output! | |
File.open(file_name, "w+") {|file| file.puts text} | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment