
ranjan.kbr
New User
Nov 6, 2008, 2:10 AM
Post #1 of 4
(2349 views)
|
|
Replacing an existing IP address with a new IP address
|
Can't Post
|
|
I want to substitute the existing IP address with a new IP address and recontruct the original string using perl . My Source File is as follows text.txt ----------- RequestURI := "sip:192.1.1.1"; From := "sip:192.1.2.3"; i need to write a perl program which will ask for the RequestURI and From address and replace the value into the text.txt file output -------- Enter the Request URI:=192.10.2.3 Enter From :=185.60.2.1 test.txt ---------- RequestURI := "sip:192.10.2.3"; From := "sip:185.60.2.1"; I have written the code as follows: #! /usr/bin/perl my $data_file = '/home/remoteuser/ranjan/text.txt'; open DATA, "$data_file" or die "can't open $data_file $!"; print "Enter the RequestURI:\n"; $RequestURI=<STDIN>; my @array_of_data = <DATA>; foreach my $line (@array_of_data) { if ($line =~ m/RequestURI/) { $line =~ s/sip:.*;/sip:$RequestURI/; open DATAOUT, ">$data_file" or die "can't open $data_file $!"; print DATAOUT "$line"; } } The code is not able to provide me the exact out put. Need some help to sort it out. |