title: sed conditionally append to line after matching pattern
body: <p>I've a file (test) with the following content which needs to edited.</p>
  
  <p><strong>test</strong></p>
  
  <pre><code>foo:
  bar:hello
  </code></pre>
  
  <p>I'm currently using sed to match a pattern and append a string to the end of line.</p>
  
  <pre><code>sed -ie "/^bar/ s/$/,there" test
  </code></pre>
  
  <p>Which is giving me the expected output i.e.</p>
  
  <pre><code>foo:
  bar:hello,there
  </code></pre>
  
  <p>But the issue is, that comma (,) should be there when the line is not ending in <code>:</code>. else it becomes like:</p>
  
  <pre><code>sed -ie "/^foo/ s/$/,there" test
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>foo:,there
  bar:hello
  </code></pre>
  
  <p><strong>Requirement:</strong></p>
  
  <pre><code>foo:there
  bar:hello
  </code></pre>
  
  <p>So is it possible by any means to check for a pattern, after matching check the last character of the line, depending on the last character, append a string to the end of the line.</p>
  
  <p>P.S.: I can't install a separate package.</p>