noway
noway

Reputation: 2585

Replace a value of a parameter in a file from Bash Script

I have this pair in my configuration file:

TheParameter="TheValue"

I am trying to replace the TheValue from a bash script like, with no luck.

sed 's/TheParameter="(.*)"/TheParameter="NewValue"/' /etc/my.conf 

Can anyone suggest the correct way?

Upvotes: 0

Views: 266

Answers (2)

Kent
Kent

Reputation: 195059

see this example:

kent$  echo 'TheParameter="TheValue"'|sed 's/\(TheParameter="\).*/\1newValue"/'
TheParameter="newValue"

Upvotes: 2

Kevin
Kevin

Reputation: 56059

sed, by default, uses basic REs, in which () are not special (don't capture or group). You either need to escape them (\(.*\)), use the -E flag (extended REs), or drop them entirely.

Upvotes: 1

Related Questions