I am trying to pass in assets/css/images to replace images in multiple files.
$list
$word
$neword
$i
echo "select files: "
read list
echo "input word to search for: "
read word
echo "input word to replace with: "
read neword
for i in $list
do
sed -i "s/${word}/${neword}/g" $i
It works for words without a /, and I can see why, but I don't know how to get around it. Anyone?
You should do like this to escape /
in sed
Try Following,
sed -i "s#${word}#${neword}#g" "$i"
or
sed -i "s~${word}~${neword}~g" "$i"
Edit: Added Quotes to Filename as Suggested by @tripleee for avoiding condition like filename contains in $i
have spaces.