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 am trying substitute text in a file with a value in a variable using sed:


sed -i "s/yyyy/$file"

but sed returns:

sed: -e expression #1, char 58: unterminated `s' command

I have also tried:

sed -i "s/yyyy/${file}"
share|improve this question

You need to "terminate" the substitution -- put a / at the end of it:


sed -i "s/yyyy/$file/"
share|improve this answer
thanks sed -i "s/yyyy/$file/" works thanks – Prasad Nov 23 '11 at 14:35

You are missing the last /.


sed -i "s/yyyy/$file/"

The syntax of the s (as in substitute) command is ‘s/regexp/replacement/flags’. The / characters may be uniformly replaced by any other single character within any given s command. The / character (or whatever other character is used in its stead) can appear in the regexp or replacement only if it is preceded by a \ character.

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.