title: find and replace a line OR add to the end of the file
body: <p>Is it possible to either find and replace a line in a file OR append a string to the end if it is not there?</p>
  
  <p>I know I can use this to <strong>find and replace</strong>:</p>
  
  <pre><code>sed -i -e "s/^SEARCH/LINE 1\nLINE 2/" file
  </code></pre>
  
  <p>I know I can <strong>append</strong> to the file like this:</p>
  
  <pre><code>cat &lt;&lt; EOF | tee -i file1 file2
  LINE 1
  LINE 2
  EOF
  </code></pre>
  
  <p>Is it possible to somehow to combine this. So if <code>/^SEARCH.*$/</code> matches then replace it, if it doesn't, then append the replacement to the end of the file.</p>
  
  <p><strong>Update with a better input/output example:</strong></p>
  
  <p>For example, if I had this input file <code>testfile</code>:</p>
  
  <pre><code>Alpha
  Bravo
  Charlie
  </code></pre>
  
  <p>Let's say I wanted to find and replace <code>Bravo</code> with <code>Bravo=bingo</code>, <strong>OR</strong> add <code>Bravo=bingo</code> if <code>Bravo</code> is not there, the expected output is:</p>
  
  <pre><code>Alpha
  Bravo=bingo
  Charlie
  </code></pre>
  
  <p>This is because <code>Bravo</code> exists in the file, so it is replaced.</p>
  
  <p>Let's say I wanted to find and replace <code>Delta</code> with <code>Delta=bingo</code>, <strong>OR</strong> add <code>Delta=bingo</code> if <code>Delta</code> is not there, the expected output is:</p>
  
  <pre><code>Alpha
  Bravo
  Charlie
  Delta=bingo
  </code></pre>
  
  <p>This is because <code>Delta</code> is not in the file so it is appended.</p>