title: Find unique string within a file, up a line and append?
body: <p>Can someone please help me with this scenario? I'm looking for a SED or AWK command that I can use to find a unique string within a config file (Linux), go up a line and append a string to the end of that line?</p>
  
  <p>For example:</p>
  
  <p><strong>config file:</strong></p>
  
  <blockquote>
    <p>define hostgroup{<br/>
            hostgroup_name  http-urls ; The name of the hostgroup<br/>
            alias           HTTP URLs ; Long name of the group<br/>
            members         domain1.com, domain2.com, domain3.com,<br/>
        #MyUniqueString<br/>
            }<br/></p>
  </blockquote>
  
  <p>In the above example, I'd like to use SED or AWK to find <strong>#MyUniqeString</strong>, go up a line that starts with <strong>members</strong> and append <strong>"domain4.com"</strong> at the end of the line.</p>
  
  <p>I found this question below but I need to search the text file first for the string, and go one line above.</p>
  
  <p><a href="https://stackoverflow.com/questions/5890052/bash-script-appending-text-at-the-last-character-of-specific-line-of-a-file">Bash script: Appending text at the last character of specific line of a file</a></p>
  
  <p>Any suggestions?</p>