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.)
精彩评论