My requirement is to replace a set of words in a given text file with a second set of words, which might be given from the command line or another file. Wanting to use Perl to do this, as the rest of my code is also in Perl.
So, if I have the following:
server name="${server1}" host="abc.com"
server name="${server2}" host="webcs.com"
server name="${server5}" host="httpvcs1.com"
server name="${server6}" host="xyz.com"
server name="${server7}" host="msg.com"
I wish to replace the strings 'server1', 'server2', 'server5', etc, with a different set of words. These might be placed in another file or given from the command line (whichever is more feasible).
Also, if, instead of just 'server1', 'server2', etc, I want to replace the 'server' word with say 'file', how would i go about making a regex for this replacement?
perl -pie 's/server\d{1-3}/myword/g' loginOut.txt > loginOut1.txt
The above will do a replacement for all words with 'myword'. But I want only the substring to be replaced.