Friday, November 26, 2010

Re: edit multiple files under multiple directories/folders



On Sat, Nov 27, 2010 at 9:50 AM, Tim Chase <vim@tim.thechases.com> wrote:
On 11/26/2010 08:36 PM, Kaushal Shriyan wrote:
In my home folder I have 6 tomcat directories under
/home/kaushal/tomcat0......6

Under each of these tomcats there are sub folder conf and
inside these conf there is a file by the name server.xml so
for example I have
tomcat0,tomcat1,tomcat2,tomcat3,tomcat4,tomcat5 so i need to
edit server.xml and set port numbers for tomcat0 to 8080
tomcat1 to 8081 and similarly for others,the other way is to
go to individual directory and do it

Please suggest/guide

Given that you appear to be on a *nix-like box, I'd be tempted to just use shell-tools to do the editing instead of vim.  You don't mention what changes you need.  However, assuming you have a server.xml containing something like "<port>8080</port>" or "<port>PORT PLACEHOLDER</port>", I'd do something like

 bash$ for i in 0 1 2 3 4 5 6; do sed -i.bak "s@<port>[^<]*</port>@<port>808${i}</port>@g" /home/kaushal/tomcat${i}/server.xml ; done


(all on one line, FWIW, and the "<port>[^<]*</port>" bit shouldn't be line-broken in case mailers between here and there mung it)  Things get a little trickier if you have more than 10 directories, but doable:

bash$ for i in `seq 0 15`; do sed -i.bak "s@<port>[^<]*</port>@<port>$((8080+i))</port>@g" /home/kaushal/tomcat${i}/server.xml ; done

This does create backups as server.xml.bak (you can omit the "-i.bak" from the sed command if you don't want backups).

Hope this helps,

-tim





Hi Tim

Thanks for the reply and suggestion. Apologies for not explaining it clearly in the first instance.


Line No 30 <Server port="8005" shutdown="SHUTDOWN"> to be changed to <Server port="8105" shutdown="SHUTDOWN">
Line No 94 <Connector port="8080" maxHttpHeaderSize="8192" to be changed to <Connector port="8081" maxHttpHeaderSize="8192"
Line No 119 <Connector port="8009"
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /> to be changed to

            <Connector port="8109"
               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

The above server.xml changes relates to tomcat1 viz... 8105,8081 and 8109 similarly it holds true for the rest of the tomcats
For example for tomcat2 it would be 8205,8082 and 8209 in server.xml

Please let me know if you need more information.

Thanks

Kaushal 

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment