title: How to use awk to insert multiple lines after first match of a pattern, in multiple files
body: <p>I have a directory containing many subdirectories, each containing a <code>config.xml</code> file I want to edit. Like:</p>
  
  <pre><code>../jobs/foo_bar-v1.2_west/config.xml
  ../jobs/foo_bar-v1.3_west/config.xml
  ../jobs/foo_stuff-v1.3_east/config.xml
  ../jobs/foo_foo-v9.8_north/config.xml
  ../jobs/NOT_FOO-v0.1_whatev/config.xml
  etc.
  </code></pre>
  
  <p>I need a way to insert multiple lines of text into several of the <code>../jobs/foo*/config.xml</code>  files, after matching the first instance of a specific line, <code>&lt;properties&gt;</code>.</p>
  
  <p>Text to insert looks like:</p>
  
  <pre><code>    &lt;a.bunch.of.TextGoesHere&gt;
        &lt;permission&gt;one.foo.Items.Foo:person.name&lt;/permission&gt;
        &lt;permission&gt;two.foo.Items.Foo:person.name&lt;/permission&gt;
        &lt;permission&gt;three.foo.Items.Foo:person.name&lt;/permission&gt;
      &lt;/a.bunch.of.TextGoesHere&gt;
  </code></pre>
  
  <p>Each <code>../jobs/foo*/config.xml</code> looks like:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;foo1&gt;
    &lt;actions/&gt;
    &lt;description&gt;foo2&lt;/description&gt;
    &lt;keepDependencies&gt;false&lt;/keepDependencies&gt;
    &lt;properties&gt;
      &lt;foo3/&gt;
    &lt;/properties&gt;
   ...
    &lt;lots_of_other_stuff&gt;
    &lt;properties&gt;
      &lt;junk&gt;
    &lt;/properties&gt;
  </code></pre>
  
  <p>Final output for each <code>config.xml</code> should look like:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;foo1&gt;
    &lt;actions/&gt;
    &lt;description&gt;foo2&lt;/description&gt;
    &lt;keepDependencies&gt;false&lt;/keepDependencies&gt;
    &lt;properties&gt;
      &lt;a.bunch.of.TextGoesHere&gt;
        &lt;permission&gt;one.foo.Items.Foo:person.name&lt;/permission&gt;
        &lt;permission&gt;two.foo.Items.Foo:person.name&lt;/permission&gt;
        &lt;permission&gt;three.foo.Items.Foo:person.name&lt;/permission&gt;
      &lt;/a.bunch.of.TextGoesHere&gt;
      &lt;foo3/&gt;
    &lt;/properties&gt;
   ...
    &lt;lots_of_other_stuff&gt;
    &lt;properties&gt;
      &lt;junk&gt;
    &lt;/properties&gt;
  </code></pre>
  
  <p>I've tried using <code>sed</code> to insert after a specific line, like </p>
  
  <pre><code>#!/bin/bash
  find ../jobs/run* -name config.xml -exec sed -i '6a\
  &lt;text to insert&gt;' {} \;
  </code></pre>
  
  <p>but occasionally, long <code>&lt;description&gt;</code> text from the <code>config.xml</code> results in an unpredictable line number on which to insert.</p>
  
  <p>Next I tried using <code>sed</code> to search for the first instance of <code>&lt;properties&gt;</code> and inserting after, like</p>
  
  <pre><code>sed -i '0,/properties/a test' config.xml
  </code></pre>
  
  <p>but this resulted in adding the <code>test</code> test after EVERY line until <code>&lt;properties&gt;</code> was found. Using <code>sed -i '1,/</code> had similar results. It was ugly.</p>
  
  <p>I'm unsure if I'm using <code>sed</code> properly on this Amazon Linux box, and am thinking <code>awk</code> might work better here. Can anyone assist? Thanks.</p>