Skip to content

Instantly share code, notes, and snippets.

@Pegolon
Created January 14, 2016 12:14
Show Gist options
  • Select an option

  • Save Pegolon/d44b518c7d47df103f43 to your computer and use it in GitHub Desktop.

Select an option

Save Pegolon/d44b518c7d47df103f43 to your computer and use it in GitHub Desktop.
Find all XML files and replace multiple strings
hash2id={"replace1":"with1","replace2":"with2"}
xml_files=`find "/path/to/folder" -type f -name '*.xml'`.strip.split("\n")
xml_files.each do |xml_file|
puts "Processing #{xml_file}"
original_text=File.read(xml_file)
text=original_text.dup
hash2id.each do |hash,id|
text.gsub!(hash.to_s, id)
end
if text!=original_text
open(xml_file, 'w') do |f|
f << text
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment