Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
Created July 3, 2013 10:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jhjguxin/5916816 to your computer and use it in GitHub Desktop.
Save jhjguxin/5916816 to your computer and use it in GitHub Desktop.
Read, edit, and write a text file line-wise using Ruby
# 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