how to replace a line in a file using shell script

I have a property file in which the DB name is specified and when i run my servers they will point to the DB specified in that property file. Now i'm gonna write a script which will start all the services. But before that i just want to dynamically change the DB name in that property file by getting as command line argument of my script. Say this is the line in that property file as

       Application.Database = snowdropDB

this line should be modified with the command line argument of my script. If i call the script like

      startup tulipDB

first the script should modify that line of the property file as

     Application.Database = tulipDB

and should start the services... plz do suggest me how to modify a line of a file thru script...:confused:

I have one suggestion.

put the DB names in a vertical file.

#vi fileDB
snowdropDB
tulipDB
etcDB.....

Then do this in your script.

#!/bin/ksh
for name in `cat fileDB`
do

startup $name #"change the name"

some other exe

some other exe

done

This script will allow you to use the different DB names.

OR you can define the DBs in an array inside the script. I prefer to have it in another file. I like modular scripting it makes it easier to make big changes without rewriting the whole program.

:cool: :smiley:

cs_sakthi,

Let prop_file is name of your property file.
File prop_file contains the following line with other contents.

Application.Database=snowdropDB

Make shell sript file startup.sh

Shell script startup.sh contains

sed "s/Application.Database=.*/Application.Database=$1/g" prop_file > tmp
mv tmp prop_file

Execute
sh startup.sh tulipDB

All occurences of snowdropDB will get replaced by tulipDB.

This I tested and it worked.

J1yant:)

Thanks for your handy script...It worked..

-Thanks
Sakthi.:slight_smile: