Im trying to replace string with variable with this command but not works

sed '/AXG/s/;/${HOMEx}/g'    

Please help me with this

  • Might help to TAG the question; Linux? Mac? – ejbytes Mar 28 '17 at 1:41
  • I put linux in tag – victorhernandezzero Mar 28 '17 at 1:42
  • my variable is HOMEx – victorhernandezzero Mar 28 '17 at 1:43
  • Oh my bad. didn't see it. – ejbytes Mar 28 '17 at 1:43

Get rid of the single quotes. They prevent variable expansion.

sed "/AXG/s/;/${HOMEx}/g"

If HOMEx="test" this becomes: sed "/AXG/s/;/test/g"

Compare https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.htm and https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html

Beware though: if the variable HOMEx contains something sed recognises you'll get an error. In this case the main things would be a backreference like "\1" or forward slash "/".

  • this give a error unknow character – victorhernandezzero Mar 28 '17 at 1:45
  • Be careful about what's in the variable though. If it contains something sed recognises you'll have problems – squashed Mar 28 '17 at 1:50
  • yes I have problems with this my variable is SO big – victorhernandezzero Mar 28 '17 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.