Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4799

Re: replace lines in a file using hash key-value pairs

From Johannes Held <johannes.held@informatik.uni-erlangen.de>
Newsgroups comp.lang.ruby
Subject Re: replace lines in a file using hash key-value pairs
Date 2011-05-20 09:37 +0200
Message-ID <93mk01F6u3U1@mid.dfncis.de> (permalink)
References <235a8d6f428573541046a02f84b60764@ruby-forum.com>

Show all headers | View raw


Something like that?

hash = {"#HOST#" => "localhost", "#PORT#" => "2020" }
fdata = File.read("config.ini")
hash.each {|key, value|	fdata.gsub(key, value) }
File.open("config_new.ini", "w") { |f| f.write(fdata) }

--
Johannes

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

replace lines in a file using hash key-value pairs Johan Martinez <jmartiee@gmail.com> - 2011-05-20 02:12 -0500
  Re: replace lines in a file using hash key-value pairs Johannes Held <johannes.held@informatik.uni-erlangen.de> - 2011-05-20 09:37 +0200
  Re: replace lines in a file using hash key-value pairs Brian Candler <b.candler@pobox.com> - 2011-05-20 03:03 -0500
  Re: replace lines in a file using hash key-value pairs Johan Martinez <jmartiee@gmail.com> - 2011-05-21 22:07 -0500

csiph-web