Wednesday, February 9, 2011

replace text in single or multiple files

1, replace all aaaa to bbbbb in file 1.xml

root@li9:/var/htdocs/sitemaps# sed -i 's/aaaa/bbbbb/g' 1.xml

2 replace all aaaa to bbbbb in files *.xml
root@li9:/var/htdocs/sitemaps# sed -i 's/2011-02-02/2011-02-09/g' *.xml


* -i : sed will directly modify the file if it finds anything to replace
* s : substitute the following text
* g : global, match all occurrences in the line

2 comments: