Skip to content
Advertisement

SED Variable contains Dollar Sign

I m having difficulty with sed, a variable contains Dollar Sign like this…

JavaScript

I am trying to ‘cleanse’ and outputfile of a password with.

JavaScript

I have tried every version of quotes you can imagine. please help.

Advertisement

Answer

Well, let us suppose you have this file:

JavaScript

If you had control over the value of the pattern, you could just escape the dollar sign:

JavaScript

Alas, we don’t have, but we can use sed to escape the variable value:

JavaScript

Fortunately, we can get the output of one command as part of another by using command substitution:

JavaScript

…so we just need to do it on our original command!

JavaScript

In this case, we just escaped one special character. There are some more on sed, so this Q&A can be helpful in the general case.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement