开发者

need script to add line to xml file

开发者 https://www.devze.com 2023-04-04 20:59 出处:网络
for all files containing a line like开发者_JAVA百科: <class name=\"blahblahblah\" foo=\"bar\" fooz=\"baz\">

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

精彩评论

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