Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to create a text file where parts of it should be replaced by any arbitrary path. I wanted to do that by copying a template file and then replace a special pattern, e.g. ${MY_PATH} with the arbitrary path (I hope, no quoting is needed). How to do that replacing part (the sed-examples I saw so far seemed to be problematic because of the arbitrary path).

share|improve this question
up vote 2 down vote accepted

The replacement doesn't need much quoting: only backslashes and the regexp separator. For convenience, the latter can often be chosen arbitrarily - instead of s/.../.../ one could, in many programs, say s|...|...| or similar.

Assuming the path is $path, you could do:

sed "s|\${MY_PATH}|$epath|g" < in > out

Or if you are not afraid of other languages, you could use:

perl -e 'my $path = shift(@ARGV); while (<STDIN>) {s|\$\{MY_PATH\}|$path|g; print}' "$path" < in

(Not sure I got the sample right, but you get the idea.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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