0

I want to remove a pattern from a string (using sed and pipes), but this pattern is not always the same and is defined previously on a variable.

this example mimics the desired behavior

toremove="Osiris"

mystring="Horus,Osiris,Apis"

mystring=$(echo $mystring | sed -e 's/$toremove//g')

no succcess so far. Output is the same as input,

jomaweb
  • 531
  • 1
    You are using ยด instead of ' as single quotes. You also don't say what actually happens and what "no success" actually means. Also note that variables are not expanded within single quotes. Is there any reason you are not doing this with bash as mystring=${mystring//$toremove/}? โ€“ Kusalananda Jun 13 '19 at 10:14
  • no success means nothing is removed. Fixed quoting. Pipes and sed are mandatory. This is a simplified example โ€“ jomaweb Jun 13 '19 at 10:22
  • 2
    Nothing will be removed because, as I mentioned, the variable is not expanded within single quotes. This question appears to be a duplicate of How can I use variables in the LHS and RHS of a sed substitution? unless there's something else that sets it apart. โ€“ Kusalananda Jun 13 '19 at 10:34

0 Answers0