bash - Using variable with sed -
first of apologise in case has been answered before couldn't solve problem.
i need search pattern , replace line of text comprising of both text , variable.btw using bash..
say
$var = "stacko.ver/rulz=" **note: $var contain double quotes & = & dot , /**
i want follow 1.search ;te.xt =
note: value search contain ; & = , dot
2.replace
textnum=$var
of course $var should replaced actual value
my attempts
sed -i "s/;te.xt =/textnum=$var/" file sed -i "s/;te.xt =/textnum="$var"/" file sed -i "s/";te.xt ="/"textnum=$var"/" file
none of these worked , either sed giving me error or value of $var not shown in file
thanks
regards
quoting doesn't since sed issue, not bash issue. pick sed s-expression delimiter doesn't appear in text:
sed -i "s|;te.xt =|textnum=$var|" file
you can pick delimiter s
doesn't appear in input. sed -e 'streetlight'
valid sed command.
Comments
Post a Comment