Created
January 14, 2016 12:14
-
-
Save Pegolon/d44b518c7d47df103f43 to your computer and use it in GitHub Desktop.
Find all XML files and replace multiple strings
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
| 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