Append line after last match with sed
<p>Let's assume I have the following input.</p>

<pre><code>Header
thing0 some info
thing4 some info
thing4 some info
thing4 some info
thing2 some info
thing2 some info
thing3 some info
</code></pre>

<p>Now, I want to be able to append "foo" on the last successful match of "thing4" like this.</p>

<pre><code>Header
thing0 some info
thing4 some info
thing4 some info
thing4 some info
foo
thing2 some info
thing2 some info
thing3 some info
</code></pre>

<p>The order is not necessarily  guaranteed, but the sequential numbering in this example is just to show that there is a searchable keyword before certain lines of text and that they are are <strong>usually</strong> grouped together on input, but it is not guaranteed.</p>