title: Conditionally add or append to a file in linux script
body: <p>I need to modify a file via a script.<br>
  I need to do the following:<br>
  IF a specific string does NOT exist then append it.  </p>
  
  <p>So I created the following script:  </p>
  
  <pre><code>#!/bin/bash  
  if grep -q "SomeParameter A" "./theFile"; then  
  echo exist  
  else  
     echo doesNOTexist  
     echo "# Adding parameter" &gt;&gt; ./theFile    
     echo "SomeParameter A" &gt;&gt; ./theFile    
  fi
  </code></pre>
  
  <p>This works but I need to make some improvements.<br>
  I think it would be better if I checked if "SomeParameter" exists and then see if it is followed by "A" or "B". If it is "B" then make it "A".<br>
  Otherwise append the string (like I do) BUT BEFORE the start of the last block of comments.<br>
  How could I do this?<br>
  I am not good in scripting.<br>
  Thanks!</p>