i using below code replacing string inside shell script.
echo $line | sed -e 's/12345678/"$replace"/g'
but it's getting replaced $replace
instead of value of variable.
could tell went wrong?
if want interpret $replace
, should not use single quotes since prevent variable substitution.
try:
echo $line | sed -e "s/12345678/\"${replace}\"/g"
assuming want quotes put in. if don't want quotes, use:
echo $line | sed -e "s/12345678/${replace}/g"
transcript:
pax> export replace=987654321 pax> echo x123456789x | sed "s/123456789/${replace}/" x987654321x pax> _
just careful ensure ${replace}
doesn't have characters of significance sed
(like /
instance) since cause confusion unless escaped. if, say, you're replacing 1 number another, shouldn't problem.
Comments
Post a Comment