I am on a Solaris 8 box that does not support -i option for sed, so I am using the followin开发者_运维知识库g from a google search on the topic:
# find . -name cancel_submit.cgi | while read file; do
> sed 's/ned.dindo.com\/confluence\/display\/CESDT\/CETS+DocTools>DOC Team/wwwin-dev.dindo.com\/Eng\/CntlSvcs\/InfoFrwk\/GblEngWWW\/Public\/index.html>EDCS Team/g' ${file} > ${file}.new
> mv ${file}.new ${file}
> done
This works except it messes up file permissions and group:owner.
How can I retain the original information?
You may use 'cat'.
cat ${file}.new > ${file} && rm ${file}.new
cp -p
preserves the stuff you want. Personally I would do this (to imitate sed -i.bak
):
...
cp -p ${file} ${file}.bak
sed 's/..../g' ${file}.bak > ${file}
...
You could add rm ${file}.bak
to the end if desired, in which case you wouldn't technically need the -p
in the cp
line above. But with the above you can do mv ${file}.bak ${file}
to recover if the replacement goes awry.
精彩评论