sed error

in a bash shell I have the following

S00="BLOCK-NAMES /ELM1 /SAUT0 /FIT00 FOR ELMT,SAMPLE,FIT"
S01="BLOCK-NAMES /ELM1 /SAUT0 /FIT01 FOR ELMT,SAMPLE,FIT"

sed "s/'$S00'/'$S00'/g" pb206.cnt > tmp

sed commplains and says
sed: -e expression #1, char 29: Unknown option to `s'

Can anybody help?
Thank you!!!

Try this

sed 's/$S00/$S01/g' pb206.cnt > tmp

instead of

sed "s/'$S00'/'$S00'/g" pb206.cnt > tmp

Thank you Shivdatta, it doesn't complain anymore but it does not replace the string!

You are replacing a string with the same string, so it's quite possible that it's replacing it, but there is no way to tell.

What exactly would you expect the result to be like?

If in case u are trying to replace FIT00 by FIT01 then if this helps

sed 's/\(.*\)FIT00\(.*\)/\1FIT01\2/g' filename

of course the strings are different:
here is the script

S00="BLOCK-NAMES /ELM1 /SAUT0 /FIT00"
S01="BLOCK-NAMES /ELM1 /SAUT0 /FIT01"
S02="BLOCK-NAMES /ELM1 /SAUT0 /FIT02"
S03="BLOCK-NAMES /ELM1 /SAUT0 /FIT03"

sed 's/$S00/$S01/g' pb206.cnt > tmp1
sed 's/$S00/$S02/g' pb206.cnt > tmp2
sed 's/$S00/$S03/g' pb206.cnt > tmp3

but tmp1, tmp2 and tmp3 are the same as pb206.cnt (which contains S00)

Shivdatta: Actually you probably mean

sed 's/FIT00/FIT01/g' filename

Your expression will replace only one occurrence (the last I believe) because of the wildcards which make it match the whole line.

But I guess what's asked for is really

sed "s%$S00%$S01%g" file

Single quotes force the strings to be taken literally; no quotes will give you a syntax error for many complex strings. To interpolate a variable into a string, put it in double quotes.

Of course, if you meant the substitution to contain literal single quotes, put them back in.

The "unknown option to s" error happens because the interpolated string contains slashes. Sed has no way to know which slashes were interpolated (this happens in the shell, before sed executes) so you need to use a different separator than the slash. (Fortunately in this case you know there are no percent signs in these variables. It's tougher when you can't know in advance whether or not a particular character could be included in a variable.)

actually i have to replace the whole string S00 with S01

to sum up I have a file containing at a certain point the string S00
and S00 is
"BLOCK-NAMES /ELM1 /SAUT0 /FIT00"

I need to replace it by
"BLOCK-NAMES /ELM1 /SAUT0 /FIT01"
"BLOCK-NAMES /ELM1 /SAUT0 /FIT02"
...
I need to replace the whole string and not only the last part

so I thought about using sed but I have some problems as it seems,

thank you all

Please check the answer replied by Era..
In case u missed it out...

Try

sed "s%$S00%$S01%g" file

Thanks for that explaination....even i thought the probs may be due to the
forward slash in the string :slight_smile:

The solution posted era works,
thank you all again!