Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying substitute text in a file with a value in a variable using sed:

file=1601001000100000003_0003_0_E_2011-11-21_16-52-16.db

sed -i "s/yyyy/$file" tempsbchg.sh

but sed returns:

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

I have also tried:

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

2 Answers 2

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

file=1601001000100000003_0003_0_E_2011-11-21_16-52-16.db

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

You are missing the last /.

Try:

sed -i "s/yyyy/$file/" tempsbchg.sh

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

 
discard

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.