Jordi Vidal
Jordi Vidal

Reputation: 23

sed replace variables while read lines

I'm working on a shell script and i need to change some strings from different lines of a file into a while read statement. The structure need to be like this, because the String_Search and String_result will be calculated on each line.

while read line 
do  
   varA="String_Search"   
   resA="String_Result"
   line=`echo $line | sed -e "s/$varA/$resA"`
   echo $line >> outputFile.txt
done < "inputFile.txt"

The script doesn't works and its showing to me this error message:

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

Anyone Can Help Me?

Thanks to All

Upvotes: 2

Views: 9409

Answers (1)

Benoit Blanchon
Benoit Blanchon

Reputation: 14561

You need to end the substitution pattern by a slash /

line=`echo $line | sed -e "s/$varA/$resA/"`

Upvotes: 5

Related Questions