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. Bash腳本啓用mod_rewrite AllowOverride全部
- 5. C#,TextBox'&'char更改爲amp;
- 6. bash腳本改進
- 7. bash腳本爲
- 8. 用bash腳本更改子網
- 9. 從bash腳本更改xterm的標題
- 10. Bash腳本來更改文件名
- 11. bash腳本每5000次更改wput uploaddirectory
- 12. 更改$到%登錄bash腳本
- 13. 在Bash腳本中更改目錄
- 14. 在bash腳本中更改目錄
- 15. 更正腳本Bash
- 16. 如何從外部更改bash腳本中的全局變量,以便更改反映在while循環中?
- 17. AMP:如何更改amp-accordion頭部的背景顏色?
- 18. 腳本是否可以更改腳本運行的bash的cwd?
- 19. 將PING腳本更改爲TELNET腳本?
- 20. Outlook更改和&
- 21. 將所有非ascii字符更改爲ascii Bash腳本
- 22. bash腳本 - 更改TRUE爲FALSE密鑰在Array
- 23. bash腳本中sqlite的安全副本
- 24. Bash腳本:粘貼並執行一個外部bash腳本
- 25. bash腳本貓更聰明
- 26. Java String用&替換'&',但不用&改爲& amp;
- 27. 防止Ruby更改爲和&?
- 28. 將csh腳本轉換爲bash腳本
- 29. bash腳本改變更改日期和時間標記
- 30. 通過腳本更改SVN外部?
'sed的-i'在原地進行編輯。 – 2011-05-25 08:11:58
真棒謝謝:D – superbly 2011-05-25 08:24:19
這會搞砸所有其他命名實體。例如,<將變爲& lt; – 2011-05-25 09:08:52