-
-
Save synsa/36a7539bfce3c76d010aa3a84ac80d94 to your computer and use it in GitHub Desktop.
Read, edit, and write a text file line-wise using Ruby
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
# http://stackoverflow.com/questions/4397412/read-edit-and-write-a-text-file-line-wise-using-ruby | |
# files = Dir.glob(File.dirname(__FILE__)+"/../app/**/*.rb") | |
files = Dir[Rails.root.join("app", "**/*.rb")] | |
files.each do |f_name| | |
# puts f_name | |
File.open(f_name, "r+") do |f| | |
old_pos = 0 | |
f.each do |line| | |
f.pos = old_pos # this is the 'rewind' | |
f.print line.gsub(/GxUserContacts/, "GxUserContact") | |
old_pos = f.pos | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment