开发者

need script to add line to xml file

for all files containing a line like开发者_JAVA百科:

 <class name="blahblahblah" foo="bar" fooz="baz">

I would like to add this line right afterwards.

 <cache usage="read-write">

The key text for searching is

  <class name=

I have access to a bash shell for this.

Thanks!


Try this one:

sed -i '/<class name=*/ a\
<cache usage="read-write">' filename.xml

and remember it is just one single command. The -i option (--in-place) changes the given file (in place).


Is Awk an option?

awk '{ print; if ($0 ~ "<class name=") print "<cache usage=\"read-write\">"; }'

(Though I still strongly object to using line-oriented tools on XML files. A decent XML toolset saves you a lot of trouble in the long run.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜