Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace a token with the result of `pwd` in sed?

Tags:

unix

sed

I'm trying to do something like this:

sed 's/#REPLACE-WITH-PATH/'`pwd`'/'

Unfortunately, I that errors out:

sed: -e expression #1, char 23: unknown option to `s'

Why does this happen?

like image 427
saffsd Avatar asked Jul 27 '09 02:07

saffsd


People also ask

How do you replace something with sed?

Find and replace text within a file using sed command The procedure to change the text in files under Linux/Unix using sed: Use Stream EDitor (sed) as follows: sed -i 's/old-text/new-text/g' input.txt. The s is the substitute command of sed for find and replace.

How do you replace a variable in a file using sed?

For replacing a variable value using sed, we first need to understand how sed works and how we can replace a simple string in any file using sed. In this syntax, you just need to provide the string you want to replace at the old string and then the new string in the inverted commas.

How do you escape a new line in sed?

The backslash (\) in the replacement string of the sed substitution command is generally used to escape other metacharacters, but it is also used to include a newline in a replacement string.


1 Answers

You need to use a different character instead of /, eg.:

sed 's?#REPLACE-WITH-PATH?'`pwd`'?'

because / appears in the pwd output.

like image 55
RichieHindle Avatar answered Sep 17 '22 17:09

RichieHindle