I'm trying to substitute a key which comes at the end of a config
file. The key is on the last line of the file following this string ";
xyzzy:" I've have a new key in the variable $key.
Here is the file:
PORTDRIVER.CFG
............
; xyzzy:9F2ECD7590CBBC281A1A8787B02F165B
Here is part of my script:
mv PORTDRIVER.CFG PORTDRIVER.CFG.$$
sed "s/; xyzzy:.* /; xyzzy:$key /" PORTDRIVER.CFG.$$ > PORTDRIVER.CFG
Our system just went down, so I can't get the exact error message, but
it was something like:
s/; xyzzy:.* /; xyzzy: cannot be parsed
Here is an example of variable substitution with sed.
>a="test"
>echo "this is test"|sed 's/'$a'/matched/g'
this is matched
Hope this helps.
Dinakar Desai
Dohh.
The problem was with the permission on the file I was trying to
update.
I spoke too soon. I'm still getting the error.
mv PORTDRIVER.CFG PORTDRIVER.CFG.tmp
sed 's/xyzzy:.*/xyzzy:'$key'/' PORTDRIVER.CFG.tmp > PORTDRIVER.CFG
The $key contains:
9F2ECD7590CBBC281A1A8787B02F165B
The line in the file looks like this:
; xyzzy:9E91C840633EAD49E0C12CEFA9745148
Also I have another problem, when I remove the variable and substitute
the actual key, it appends the new key to the end of the line:
; xyzzy:
9E91C840633EAD49E0C12CEFA97451489F2ECD7590CBBC281A1A8787B02F165B
$cat test_data
xyzzy:9E91C840633EAD49E0C12CEFA9745148
xyzzy:9E91C840633EAD49E0C12CEFA9745148
$key="testing_substitution"
$sed 's/xyzzy.*/xyzzy:'$key'/g' test_data
xyzzy:testing_substitution
xyzzy:testing_substitution
HTH
Dinakar Desai