2
A
回答
3
您只需通过sed
过滤器来传递文件,如下面的成绩单:
$ echo '
this is line 1
this is line 2 with a & character.
and this is line 3 with & and & on it' | sed 's/&/&/g'
this is line 1
this is line 2 with a & character.
and this is line 3 with & and & on it
要使用一组文件做到这一点,你可以(当然有备份)使用就地变种:
sed -i.bak 's/&/&/g' *.xml
3
的sed可以在当前工作目录中的所有文件为你做的就地更换,
sed -i 's/&/&/g' *
如果你希望它去的多级系统,像
for file in `find`; do sed -i 's/&/&/g' $file; done
如果你只希望做与.xml扩展,这可能是有用的文件替换,做
for file in `find -iname '*.xml'`; do sed -i 's/&/&/g' $file; done
2
!/bin/bash
startdirectory="/home/jack/tmp/tmp2"
searchterm="&"
replaceterm="&"
for file in $(grep -l -R $searchterm $startdirectory)
do
sed -e "s/$searchterm/$replaceterm/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
echo "Modified: " $file
done
echo "Done!"
相关问题
- 1. 更改解释bash脚本
- 2. Google脚本中的JDBC“&”改为“&”
- 3. Bash脚本 - Crontab完成bash脚本的一部分但不是全部
- 4. C#,TextBox'&'char更改为amp;
- 5. bash脚本每5000次更改wput uploaddirectory
- 6. 在Bash脚本中更改目录
- 7. Bash脚本来更改文件名
- 8. 更改$到%登录bash脚本
- 9. bash脚本为
- 10. 更正脚本Bash
- 11. AMP:如何更改amp-accordion头部的背景颜色?
- 12. 将所有非ascii字符更改为ascii Bash脚本
- 13. bash脚本 - 更改TRUE为FALSE密钥在Array
- 14. Outlook更改和&
- 15. bash脚本猫更聪明
- 16. Java String用&替换'&',但不用&改为& amp;
- 17. 防止Ruby更改为和&?
- 18. bash脚本改变更改日期和时间标记
- 19. 通过脚本更改SVN外部?
- 20. 格式化需要更改bash脚本中的文本文件
- 21. 编写bash脚本来更改文本并写入日志
- 22. 用于安全传输的Bash脚本
- 23. 脚本中的全球bash别名
- 24. 更改&到&在php类
- 25. VB.net:如何更改amp;到&
- 26. 在ListView中更改EditText更改全部
- 27. 为什么包含&的地址全部打印为&
- 28. JavaScript更改脚本
- 29. 将app.config更改为MSBuild脚本的一部分
- 30. bash脚本删除旧部署
'sed的-i'在原地进行编辑。 – 2011-05-25 08:11:58
真棒谢谢:D – superbly 2011-05-25 08:24:19
这会搞砸所有其他命名实体。例如,<将变为& lt; – 2011-05-25 09:08:52