0

I need to replace a word between the quotes after equal sign using sed. but I'm unable to do it please suggest? #mfsbsd.rootpwhash="" look like #mfsbsd.rootpwhash="wsnk&*32jk"

cat loader | sed -e 's|["\'']||g' | sed 's/rootpwhash="[^"]*"/rootpwhash="abcd"/'

3 Answers3

0

Maybe a matter of systematically escaping the " with the \ character? This works for me:

$ echo Name=\"\" | sed -e 's/\"\"/\"This should be filled in\"/'Name="This should be filled in"

To replace anything that is originally between the "":

$ echo Name=\"Original\" | sed -e 's/\".*\"/\"This should be filled in\"/'
Name="This should be filled in"
vanadium
  • 97,564
0

If your key-value pair is structured one per line, you only need to match the key-part. i.e., if you don't have to match the value too.

text=new; cat loader | \
sed "s/\(mfsbsd.rootpwhash\)=.*/\1=\"$text\"/"
0

You can use double quotes, and escape special characters in your substitute variable

$ export TESTVAR="wsnk\&\*32jk"
$ cat loader | sed -e "s/\".*\"/\"$TESTVAR\"/"
#mfsbsd.rootpwhash="wsnk&*32jk"