sed special characters issues

I am dusting off the sed cobwebs and had a basic question:

I have a file that contains:

$firewall = "on";
$cache = "on";
$dataset{'mary had a little lamb'} = "on";

and want to only change the contents of what is between the single quotes:

$dataset{'big bad wolf'} = "on";

I tried several combinations but to no evail:

sed 's/^\$dataset{'*'} = "on"\;/\$dataset{'big bad wolf'} = "on"\;/' test.txt
sed "s@^$dataset{'*'} = "on";@$dataset{'big bad wolf'} = "on";@" test.txt
sed 's@^*$@&'big bad wolf' test.txt

So essentially saying, whatever sed finds whats in between the single quotes replace it with "big bad wolf"

Someone please enlighten me!

sed "s/'.*'/'big bad wolf'/" yourfile

or

sed "s/['].*[']/'big bad wolf'/" yourfile
#cat tst
$dataset{'big bad wolf'} = "on";
#sed "s/'.*'/'TST'/" tst
$dataset{'TST'} = "on";
#

Thanks for the reply. I should have added the complete text file but there are other variables in the file and I want to just look for only this occurrence of:

so:

$firewall = "on";
$cache = "on";
$dataset{'mary had a little lamb'} = "on";

Would this apply?

---------- Post updated at 02:29 PM ---------- Previous update was at 02:25 PM ----------


sed "/dataset/ s/'[^']*'/'new text'/" infile

this works but I need some clarification of the context of it.

sed "/pattern/s/'[^']*'/'new text'/" infile

if a line contain the pattern then the substitution apply otherwise the line is just diplayed without substitution

1 Like