Sed Issue

Hi,

I am trying to use 3 sed statements in a shell script, but it get foll error.
sed : garbage after command.

If I use only two sed statements, the script works well.
Is there any restriction for sed usage or is there some catch which I am missing.

Sample Script is as follows :

instance=a
pattern=b
filename=/opt/gate/test.txt
line="Some INSTANCE PATTERN LOGFILENAME"
line1=`echo $line | sed -e "s/INSTANCE/${instance}-${pattern}/g"`
line2=`echo $line1 | sed -e "s/PATTERN/${pattern}/g"`
line3=`echo $line2 | sed -e "s/LOGFILENAME/${filename}/g"`
echo $line3 >> ./${pattern}-${instance}.cfg

Any help is highly appreciated

Thanks,
Sameer Salve

Hi.

Your filename contains forward slashes.

This is confusing sed.

Change your sed separators to something else.

i.e.

line3=`echo $line2 | sed -e "s+LOGFILENAME+${filename}+g"`

(and please use code tags in future - it makes life easier! thx)

sed replace format can be used with any separator.. it could be any char as you like. just try to avoid chars showing from variables.

sed 's|string1|string2|g'
sed 's/string1/string2/g'
sed 'szstring1zstring2zg'

Thanks a lot !!! :b: it works.