Insert file content via sed after two searchings

Hi folks,

The file webcache.xml contains a lot sections which begins and ends with the string </CACHEABILITYRULE>.

The section In need to deel with is:

       </CACHEABILITYRULE>
        <CACHEABILITYRULE NAME="cache swf" CACHE="YES" COMMENT="This rule caches all .swf files. This file format is sufficiently compressed and should *not* be further compressed by Web Cache." COMPRESS="NO" ENABLED="YES" COMPRESSFORNETSCAPE="YES" CANOUTPUTESI="YES" SSLONLY="NO" Key="NAME">
          <SELECTORS>
            <URLEXP EXP=".swf" TYPE="FILEEXT" Key="EXP"/>
            <HTTPMETHODS SIMPLEGET="YES" GETWITHQUERYSTRING="NO" POST="NO"/>
          </SELECTORS>
          <EXPIRATIONREF EXPREF="EXPID.2"/>
        </CACHEABILITYRULE>

I need to do the following:

  1. find the string: NAME="cache swf"
  2. find the first appearance of the string </CACHEABILITYRULE> after the string NAME="cache swf"
  3. insert the file suifw_rules.xml right after the string </CACHEABILITYRULE> ,which I found in paragraph 2

I know how to insert a file after a string but I don't know how to insert a file after two searchings .

Thanks a lot in advance,
Nir

Try this.

sed -e '/.*NAME\=\"cache swf\".*/,/<\/CACHEABILITYRULE>/{
/<\/CACHEABILITYRULE>/r suifw_rules.xml
}' nir.txt

nir.txt is

       </CACHEABILITYRULE>
        <CACHEABILITYRULE NAME="cache swf" CACHE="YES" COMMENT="This rule caches all .swf files. ...  Key="NAME">
          <SELECTORS>
            <URLEXP EXP=".swf" TYPE="FILEEXT" Key="EXP"/>
            <HTTPMETHODS SIMPLEGET="YES" GETWITHQUERYSTRING="NO" POST="NO"/>
          </SELECTORS>
          <EXPIRATIONREF EXPREF="EXPID.2"/>
        </CACHEABILITYRULE>

vino

Hey vino my friend,

As always,you helped me a lot!
Thanks!!
It works perfect!!

Best regards,
Nir