0

How can escape the literal string #!/bin/bash in a sed expression? Curently I have a command in a bash script of the form

sed 's/Parametersettings:/HERE/g' outpad1 > outpad2

I would like the escaped replacement to go where HERE is written in the above.

I have tried all sorts of / \ and $variables with no luck so far.

2 Answers 2

3
$ echo 'Parametersettings:' | sed 's/Parametersettings:/#!\/bin\/bash/g'
#!/bin/bash

or use a different delimiter, avoiding the need to escape the / characters:

$ echo 'Parametersettings:' | sed 's%Parametersettings:%#!/bin/bash%g'
#!/bin/bash
0
2

By quoting your string with single quotes ("''"), you PREVENT interpolation by the shell. Use double quotes ("") and the shell will substitute variables, etc.

sed "s/Parametersettings:/$HERE/g" outpad1 > outpad2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .