I try to use sed
command inside a loop to replace IP address, but it is always giving me this error:
sed: -e expression #1, char 15: unterminated
s' command`
even it is not missing the end slash.
Example format of the IP address: 26.236.16.233
Here is my code:
readarray thearray < /root/scripts/ipaddr.info
Filepath=/var/named/chroot/var/named/$Serverdmn
for item in ${!thearray[@]}; do
echo -e "IP: ${thearray[$item]}."
echo -e "Change this IP? (y/n)"
read Useranswer
if [ $Useranswer = y ]; then
echo -e "Please type the IP address:"
read Firstipaddress
oldipaddr=${thearray[$item]}
new_oldipaddr=${oldipaddr%.*}.0
newipaddr=$Firstipaddress
new_ipaddr=${newipaddr%.*}.0
# do the change on all files
sed -i "s/$oldipaddr/$Firstipaddress/g" /root/scripts/ipaddr.info
sed -i "s/$oldipaddr/$Firstipaddress/g" /etc/application/config
sed -i "s/$oldipaddr/$Firstipaddress/g" $Filepath
sed -i "s/$new_oldipaddr/$new_ipaddr/g" $Filepath
elif [ $Useranswer = n ]; then
:
fi
done
What will be the problem here and how to solve it?
$oldipaddr
,$Firstipaddress
,$new_oldipaddr
, and$new_ipaddr
before the calls tosed
to see what you're passing to the application. Do those variables have any unexpected symbols?