Click to See Complete Forum and Search --> : replacing a string within a file


xs411
06-12-2001, 07:00 PM
I am trying to set up automatic multiple instances of the Resin server and hence I have to make each instance listen on a different port. In order to do that I need to be able to create a configuration file for each one and I need to insert the port number into the middle of the file. I can't append to the end because it has to be located in a certain place. So I'm wondering what I could use to replace say a string like 'xxxx' with '8080'. I'm using shell scripts so I'd prefer to use some unix tool.

Thanks,
XS411

jemfinch
06-12-2001, 07:49 PM
perl -pi -e s/xxxx/8080/ <file>

Jeremy

Craig McPherson
06-12-2001, 08:02 PM
This is what I do with Apache: in a file called httpd.template, I have a string IPGOESHERE. Then I just use a simple sed command:

cat /etc/apache/httpd.template | sed "s/IPGOESHERE/$IP/" > /etc/apache/httpd.conf

That makes a copy of the file, replacing IPGOESHERE with whatever the $IP variable is set to.

Craig McPherson
06-12-2001, 08:04 PM
Yeah, Perl can replace Sed and Awk and just about every other tool on your system, but Sed is just so retro!! Perl won't be retro for another 5 years or so...

[ 12 June 2001: Message edited by: Craig McPherson ]