Forums Register Login

Find and replace tokens for a project code using shell script

+Pie Number of slices to send: Send
I am trying to write a shell script that finds and replaces the tokens with the required values:

rename.properties will contain:

@server@=hostname
@port@=7001
Directory=/tmp/code

rename.sh should be able to find these tokens in the folders and subfolders under the directory mentioned in the rename.properties.

Please suggest.
+Pie Number of slices to send: Send
Here is what i have worked out :
***************************************************************************
. /home/oracle/devapp.properties
serverold=$serverold
servernew=$servernew
portold=$portold
portnew=$portnew


grep -rl "$serverold" ./ | xargs sed -i "s/$serverold/$servernew/g"
grep -rl "$portold" ./ | xargs sed -i "s/$portold/$portnew/g"
***************************************************************************

But the concern is i am unable to replace when hostnames are under .jar.
+Pie Number of slices to send: Send
Welcome to JavaRanch.

i am unable to replace when hostnames are under .jar.



Does that mean you want to alter the contents of jar files? An approach like this will only work for text files - you would need to extract the jar file (and any other archive and compression formats like tar, zip gzip etc.), run the script recursively over the contents, and then jar (tar, zip, gzip, etc.) the file back together.
+Pie Number of slices to send: Send
Hi Marshal,

That would be great if you can help me in replacing the .jar files in the same script?.
+Pie Number of slices to send: Send
As I said, you need to unjar them, run the replacement command, and then jar them back together. Type "jar" at the command line to learn about all the jar tool options.
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1272 times.
Similar Threads
Shell scripts find n replace the word in files
Problem with Installation of Luntbuild
jdk1.3.0_02 PATH????????????
How to detect a config file when using a shell script to start the app
store the output of "find" command in a variable?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:43:28.