Hello All,
I want to write a script by which I can open up a text file,scan
through it,find the line which contains the word 'test_site',get the
IP address corresponding to that word, replace that IP with another IP
address and then save and close the file.
Are there any commands in Ruby to identify IP address from a string?
text=IO.read(filename_of_file_with_ip)
text.gsub!(/test_site\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i,"0.0.0.0") #
0.0.0.0 - it's my new ip
f=File.new("outtxt","w")
f.write(text)
f.close
···
On Mon, Nov 8, 2010 at 3:20 PM, Chandu80 <chandu.shenoy@gmail.com> wrote:
Hello All,
I want to write a script by which I can open up a text file,scan
through it,find the line which contains the word 'test_site',get the
IP address corresponding to that word, replace that IP with another IP
address and then save and close the file.
Are there any commands in Ruby to identify IP address from a string?
Hello All,
I want to write a script by which I can open up a text file,scan
through it,find the line which contains the word 'test_site',get the
IP address corresponding to that word, replace that IP with another IP
address and then save and close the file.
Are there any commands in Ruby to identify IP address from a string?
Hi,
Thanks for the response.It did work.However isn't there a provision to
edit the same file and save it?
Regards
Chandrika
···
On Nov 8, 5:48 pm, Alexey Bovanenko <a.bovane...@gmail.com> wrote:
[Note: parts of this message were removed to make it a legal post.]
Hi!
I think you can use the following code:
text=IO.read(filename_of_file_with_ip)
text.gsub!(/test_site\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i,"0.0.0.0") #
0.0.0.0 - it's my new ip
f=File.new("outtxt","w")
f.write(text)
f.close
On Mon, Nov 8, 2010 at 3:20 PM, Chandu80 <chandu.she...@gmail.com> wrote:
> Hello All,
> I want to write a script by which I can open up a text file,scan
> through it,find the line which contains the word 'test_site',get the
> IP address corresponding to that word, replace that IP with another IP
> address and then save and close the file.
> Are there any commands in Ruby to identify IP address from a string?