tags:

views:

263

answers:

3

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?

+2  A: 

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

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

because / appears in the pwd output.

RichieHindle
+1  A: 
sed 's:#REPLACE-WITH-PATH:'`pwd`':' config.ini

The problem is one of escaping the output of pwd correctly. Fortunately, as in vim, sed supports using a different delimiter character. In this case, using the colon instead of slash as a delimiter avoids the escaping problem.

saffsd
A: 

instead of fumbling around with quotes like that, you can do it like this

#!/bin/bash
p=`pwd`
# pass the variable p to awk
awk -v p="$p" '$0~p{ gsub("REPLACE-WITH-PATH",p) }1' file >temp
mv temp file

or just bash

p=`pwd`
while read line
do
    line=${line/REPLACE-WITH-PATH/$p}
    echo $line    
done < file > temp
mv temp file
ghostdog74