Created
July 3, 2013 10:09
-
-
Save jhjguxin/5916816 to your computer and use it in GitHub Desktop.
Read, edit, and write a text file line-wise using Ruby
This file contains 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