Sed problem
am 05.10.2007 02:47:05 von mcbalagtas
You guys were so helpful last time. I have another problem I hope you
can help me with.
I have a config file with a key at end of the file which looks like
this:
; xyzzy:9F2ECD7590CBBC281A1A8787B02F165B
The key is everything after the ':'
Another part of my script generates the key and stores it in a
variable called:
$key
When I echo $key I the correct key:
9E91C840633EAD49E0C12CEFA9745148
My initial attempt was this:
sed 's/^; xyzzy:.*/; xyzzy:'$key'/' PORTDRIVER.CFG.$$ > PORTDRIVER.CFG
I got this error:
sed: Function s/^; xyzzy:.*/; xyzzy: cannot be parsed.
If I replace the $key with its actual value, it works ok.
sed 's/^; xyzzy:.*/; xyzzy:9E91C840633EAD49E0C12CEFA9745148/'
PORTDRIVER
..CFG.$$ > PORTDRIVER.CFG
I thought it was a variable expansion problem, but when I used an
example someone gave me it worked:
a="test"
echo "this is test"|sed 's/'$a'/matched/g'
Re: Sed problem
am 05.10.2007 04:49:06 von Icarus Sparry
On Fri, 05 Oct 2007 00:47:05 +0000, mcbalagtas@yahoo.com wrote:
> You guys were so helpful last time. I have another problem I hope you
> can help me with.
>
> I have a config file with a key at end of the file which looks like
> this:
>
> ; xyzzy:9F2ECD7590CBBC281A1A8787B02F165B
>
> The key is everything after the ':'
>
> Another part of my script generates the key and stores it in a variable
> called:
>
> $key
>
> When I echo $key I the correct key:
>
> 9E91C840633EAD49E0C12CEFA9745148
>
> My initial attempt was this:
>
> sed 's/^; xyzzy:.*/; xyzzy:'$key'/' PORTDRIVER.CFG.$$ > PORTDRIVER.CFG
>
> I got this error:
>
> sed: Function s/^; xyzzy:.*/; xyzzy: cannot be parsed.
>
> If I replace the $key with its actual value, it works ok.
>
> sed 's/^; xyzzy:.*/; xyzzy:9E91C840633EAD49E0C12CEFA9745148/' PORTDRIVER
> .CFG.$$ > PORTDRIVER.CFG
>
> I thought it was a variable expansion problem, but when I used an
> example someone gave me it worked:
>
> a="test"
> echo "this is test"|sed 's/'$a'/matched/g'
Your "initial attempt" looks fine. Does the variable $key have a newline
at the start of it? This would explain the error message.
Re: Sed problem
am 05.10.2007 18:14:02 von mcbalagtas
On Oct 4, 7:49 pm, Icarus Sparry wrote:
> On Fri, 05 Oct 2007 00:47:05 +0000, mcbalag...@yahoo.com wrote:
> > You guys were so helpful last time. I have another problem I hope you
> > can help me with.
>
> > I have a config file with a key at end of the file which looks like
> > this:
>
> > ; xyzzy:9F2ECD7590CBBC281A1A8787B02F165B
>
> > The key is everything after the ':'
>
> > Another part of my script generates the key and stores it in a variable
> > called:
>
> > $key
>
> > When I echo $key I the correct key:
>
> > 9E91C840633EAD49E0C12CEFA9745148
>
> > My initial attempt was this:
>
> > sed 's/^; xyzzy:.*/; xyzzy:'$key'/' PORTDRIVER.CFG.$$ > PORTDRIVER.CFG
>
> > I got this error:
>
> > sed: Function s/^; xyzzy:.*/; xyzzy: cannot be parsed.
>
> > If I replace the $key with its actual value, it works ok.
>
> > sed 's/^; xyzzy:.*/; xyzzy:9E91C840633EAD49E0C12CEFA9745148/' PORTDRIVER
> > .CFG.$$ > PORTDRIVER.CFG
>
> > I thought it was a variable expansion problem, but when I used an
> > example someone gave me it worked:
>
> > a="test"
> > echo "this is test"|sed 's/'$a'/matched/g'
>
> Your "initial attempt" looks fine. Does the variable $key have a newline
> at the start of it? This would explain the error message.
Thanks. That looks like my problem. How do I remove the newline from
the variable?
Here is the code that captures the key:
key="
$(awk '
/Digital Signature/ { print $5 ; } '
key.txt)"
Re: Sed problem
am 05.10.2007 18:25:35 von Icarus Sparry
On Fri, 05 Oct 2007 16:14:02 +0000, mcbalagtas@yahoo.com wrote:
> On Oct 4, 7:49 pm, Icarus Sparry wrote:
>> On Fri, 05 Oct 2007 00:47:05 +0000, mcbalag...@yahoo.com wrote:
>> > You guys were so helpful last time. I have another problem I hope you
>> > can help me with.
>>
>> > I have a config file with a key at end of the file which looks like
>> > this:
>>
>> > ; xyzzy:9F2ECD7590CBBC281A1A8787B02F165B
>>
>> > The key is everything after the ':'
>>
>> > Another part of my script generates the key and stores it in a
>> > variable called:
>>
>> > $key
>>
>> > When I echo $key I the correct key:
>>
>> > 9E91C840633EAD49E0C12CEFA9745148
>>
>> > My initial attempt was this:
>>
>> > sed 's/^; xyzzy:.*/; xyzzy:'$key'/' PORTDRIVER.CFG.$$ >
>> > PORTDRIVER.CFG
>>
>> > I got this error:
>>
>> > sed: Function s/^; xyzzy:.*/; xyzzy: cannot be parsed.
>>
>> > If I replace the $key with its actual value, it works ok.
>>
>> > sed 's/^; xyzzy:.*/; xyzzy:9E91C840633EAD49E0C12CEFA9745148/'
>> > PORTDRIVER .CFG.$$ > PORTDRIVER.CFG
>>
>> > I thought it was a variable expansion problem, but when I used an
>> > example someone gave me it worked:
>>
>> > a="test"
>> > echo "this is test"|sed 's/'$a'/matched/g'
>>
>> Your "initial attempt" looks fine. Does the variable $key have a
>> newline at the start of it? This would explain the error message.
>
> Thanks. That looks like my problem. How do I remove the newline from the
> variable?
key=${key#?}
is one way.
> Here is the code that captures the key:
>
> key="
> $(awk '
> /Digital Signature/ { print $5 ; } '
> key.txt)"
In this case you are putting in the newline yourself, it is the one
vetween the first double quote and the first dollar. Change it to read
key="$(awk '
and that should fix it.
Re: Sed problem
am 05.10.2007 18:38:28 von mcbalagtas
On Oct 5, 9:25 am, Icarus Sparry wrote:
> On Fri, 05 Oct 2007 16:14:02 +0000, mcbalag...@yahoo.com wrote:
> > On Oct 4, 7:49 pm, Icarus Sparry wrote:
> >> On Fri, 05 Oct 2007 00:47:05 +0000, mcbalag...@yahoo.com wrote:
> >> > You guys were so helpful last time. I have another problem I hope you
> >> > can help me with.
>
> >> > I have a config file with a key at end of the file which looks like
> >> > this:
>
> >> > ; xyzzy:9F2ECD7590CBBC281A1A8787B02F165B
>
> >> > The key is everything after the ':'
>
> >> > Another part of my script generates the key and stores it in a
> >> > variable called:
>
> >> > $key
>
> >> > When I echo $key I the correct key:
>
> >> > 9E91C840633EAD49E0C12CEFA9745148
>
> >> > My initial attempt was this:
>
> >> > sed 's/^; xyzzy:.*/; xyzzy:'$key'/' PORTDRIVER.CFG.$$ >
> >> > PORTDRIVER.CFG
>
> >> > I got this error:
>
> >> > sed: Function s/^; xyzzy:.*/; xyzzy: cannot be parsed.
>
> >> > If I replace the $key with its actual value, it works ok.
>
> >> > sed 's/^; xyzzy:.*/; xyzzy:9E91C840633EAD49E0C12CEFA9745148/'
> >> > PORTDRIVER .CFG.$$ > PORTDRIVER.CFG
>
> >> > I thought it was a variable expansion problem, but when I used an
> >> > example someone gave me it worked:
>
> >> > a="test"
> >> > echo "this is test"|sed 's/'$a'/matched/g'
>
> >> Your "initial attempt" looks fine. Does the variable $key have a
> >> newline at the start of it? This would explain the error message.
>
> > Thanks. That looks like my problem. How do I remove the newline from the
> > variable?
>
> key=${key#?}
>
> is one way.
>
> > Here is the code that captures the key:
>
> > key="
> > $(awk '
> > /Digital Signature/ { print $5 ; } '
> > key.txt)"
>
> In this case you are putting in the newline yourself, it is the one
> vetween the first double quote and the first dollar. Change it to read
>
> key="$(awk '
>
> and that should fix it.
Thanks. that was it.