• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Find and replace tokens for a project code using shell script

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Raj Ms
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Raj Ms
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marshal,

That would be great if you can help me in replacing the .jar files in the same script?.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic