Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SED problem

0 views
Skip to first unread message

mcbal...@gmail.com

unread,
Oct 3, 2007, 8:39:49 PM10/3/07
to
I'm trying to use a variable to work with _sed_. I did a search on the
group and using double quotes, but it still doesn't work. I tried the
man for ksh, but it didn't have any info on quotes.Now, I'm not sure
it is a problem with the variable substitution.

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

des...@gmail.com

unread,
Oct 3, 2007, 9:22:40 PM10/3/07
to

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


Bill Marcum

unread,
Oct 4, 2007, 10:19:56 AM10/4/07
to
On 2007-10-04, mcbal...@gmail.com <mcbal...@gmail.com> wrote:
>
> 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
>
If $key coontains any slashes, use a different delimiter.

mcbal...@gmail.com

unread,
Oct 4, 2007, 12:44:48 PM10/4/07
to

Dohh.

The problem was with the permission on the file I was trying to
update.


mcbal...@gmail.com

unread,
Oct 4, 2007, 2:33:42 PM10/4/07
to

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


des...@gmail.com

unread,
Oct 4, 2007, 11:34:37 PM10/4/07
to

$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

0 new messages