sed replace variables while read lines

微笑、不失礼 提交于 2020-01-25 00:06:44

问题


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


回答1:


You need to end the substitution pattern by a slash /

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


来源:https://stackoverflow.com/questions/18717302/sed-replace-variables-while-read-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!