开发者

find and replace a string in a set of xml files using shell commands

开发者 https://www.devze.com 2022-12-09 17:23 出处:网络
I have 1000 files in a directory. I\'m on a solaris machine I want to replace the string \" /example/test/temp \" t0 \" /testing/in/progress/ in all the xml file开发者_如何学编程s in my directory.

I have 1000 files in a directory. I'm on a solaris machine

I want to replace the string " /example/test/temp " t0 " /testing/in/progress/ in all the xml file开发者_如何学编程s in my directory.

any pointers will be great.

thanks,

novice


How about (all on one line):

find . \( -type d ! -name . -prune \) -o \( -type f -name "*.xml" -print \) |
    xargs perl -i.old -p -e 's-/example/test/temp-/testing/in/progress/-g'


Use sed(1).

In general it is safer to use an xslt processor to massage XML files, but in this particular example, the chances of some "funky" XML representation causing problems is pretty remote ...

0

精彩评论

暂无评论...
验证码 换一张
取 消