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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -