I need to modify a file via a script.  

I need to do the following:  

IF a specific string does NOT exist then append it. 

So I created the following script: 

```
#!/bin/bash  
if grep -q "SomeParameter A" "./theFile"; then  
echo exist  
else  
   echo doesNOTexist  
   echo "# Adding parameter" >> ./theFile    
   echo "SomeParameter A" >> ./theFile    
fi

```

This works but I need to make some improvements.  

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".  

Otherwise append the string (like I do) BUT BEFORE the start of the last block of comments.  

How could I do this?  

I am not good in scripting.  

Thanks!