我想仅在文件夹的子文件夹中存在的xml文件中用"选择最佳答案"替换字符串"解决问题".我编写了一个脚本来帮助我做到这一点,但有两个问题
那么请你帮我修改我现有的脚本,以便我可以解决上述3个问题.
我的脚本是:
find -type f | xargs sed -i"s /解决问题/选择最佳答案/ g"
使用bash和sed:
search='Solve the problem'
replace='Choose the best answer'
for file in `find -name '*.xml'`; do
grep "$search" $file &> /dev/null
if [ $? -ne 0 ]; then
echo "Search string not found in $file!"
else
sed -i "s/$search/$replace/" $file
fi
done
Run Code Online (Sandbox Code Playgroud)