Need help in sed command ( Replacing a pattern inside a file with a variable value )

Hello,

The following sed command is giving error
sed: -e expression #1, char 13: unknown option to `s'

The sed command is
echo "//-----" | sed "s/\/\/---*/$parChk/g"

where parChk="//---ee-"

How can i print the variable value from sed command ?
And is it possible to replace a specified line without ruining other lines ?

I am trying to write a script that replaces the

//---- (dashes upto < 79 coloumns) pattern to //---- (dashes upto 79 which is standard) inside any *.cpp file.

Kindly help &
Thanks in advance.
:):confused:

Try changing the delimiter from / to +.

echo "//-----" | sed "s+//---*+$parChk+g"

If you want to change a particular line or a range of lines

echo "//-----" | sed "L1,L2s+//---*+$parChk+g"

where L1 is the first line number of the range-of-lines you want to change. L2 is the ending line number of the range-of-lines you want to change. If you want only a particular line to be changed, then L1 and L2 will remain the same.

Hello,

The below script is supposed to replace partition lines "//------" in a cpp source code. Based on the previous posts i changed the sed command accordingly. But now i am stuck up with another issue ....the sed command is found not accepting $x,$x before 's'. I gave the line number as such instead of $x and it worked.

Kindly help me in solving this problem. I want to change the multiple lines (line number given by $x from for loop) of a source file. strMatch is another script that returns a set of line numbers where the pattern is found.

srcCode=$1
parStr="//-----------------------------------------------------------------------------"
parStr="--- TESTING-BAS-BAS-TESTING ---"
linNum=`strMatch $1 "//----" | tr -d ':/-'`

for x in $linNum; do
cecho green "Replacing partition on line $x ..."
cat $1 | sed "$x,$xs+//---*+$parStr+g" > $1.tmp
done
exit
:):confused: