Changing contents of a specific parameter in a file through shell script [duplicate]

Solution for Changing contents of a specific parameter in a file through shell script [duplicate]
is Given Below:

I have a file called local.conf:

db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost:3306/xyz31"
db.default.user="ron"
db.default.password=""

Here xyz31 is the variable ${DB_NAME}. I need to update only the ${DB_NAME} which is xyz31 (in this instance), but which varies depending on what the current of value ${DB_NAME} is, and which needs to be updated to whatever value the user has entered, for ex:abc22.

db.default.driver="com.mysql.jdbc.Driver"
db.default.url="jdbc:mysql://localhost:3306/abc22"
db.default.user="ron"
db.default.password=""

Is there a way to achieve this?

Use an editor like Unix’ sed(1):

  sed -i -e 's;xyz31;abc22; /your/funny/file/here

Might need to decorate with word beginning/end to avoid false positive matches (check your manual what is available). And/or write out another file and check with diff(1) that the change is right.

sed should be enough:

i=abc22 # or input from user by read i
sed "/^db.default.url/s/$DB_NAME/$i/" local.conf

Add -i option if you want to make change to the file.