Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SED

Status
Not open for further replies.

111101101

Programmer
Oct 16, 2003
39
US
Can somebody use SED or other linux command to write me a script that will change all the IP address in a file to another IP. For example, if i type...

$ replace httpd.conf 12.34.56.78 99.99.99.99

this will replace all the IP in the file httpd.conf from 12.34.56.78 to 99.99.99.99

and it should leave the rest of the file intact.

Thanks.
755
 
use perl to write file 'subst.pl'

#!/usr/bin/perl -w

while (<>) {
s/12\.34\.56\.78/99\.99\.99\.99/;
print;
}


execute it by

'perl subst.pl < httpd.conf'

it will echo out the modified httpd.conf,
which you could '> httpd.conf.new' as part of the command line.

thus
'perl subst.pl < httpd.conf > httpd.conf.new'

good luck.

Surfinbox.com Business Internet Services - National Dialup, DSL, T-1 and more.
 
Another way to skin the same cat:
perl -pi.bak -e 's/<old ip>/<new ip>/e' httpd.conf

Really ought to escape the periods in the ip address, but it works for a quick and dirty fix. The original file will be copied to httpd.conf.bak too. This is the only perl command I know, and I am so thankful for the day I ran accross it :)

----
JBR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top