title: Appending text to the end of a previous line with sed
body: <p>and thanks for considering my question! </p>
  
  <p>I have nagios config files in this format:</p>
  
  <pre><code>define host{
      use             generic-camera
      host_name       camera_7
      alias           camera facing the 7th door at headquarters
      address         172.16.202.21
      parents         hq_switch
      hostgroups      cameras,fixed-cameras
      }
  </code></pre>
  
  <p>What I would like to accomplish is to use sed to match the IP address, and append text to the line before it. I've seen plenty of suggestions how to append text to a line that matches a regex, but not how to append to the previous. I would like to append the MAC address of the IP listed under address to the alias line. This is what I would like things to look after sed has been run:</p>
  
  <pre><code>define host{
      use             generic-camera
      host_name       camera_7
      alias           camera facing the 7th door at headquarters MAC 00:01:02:aa:bb:cc
      address         172.16.202.21
      parents         hq_switch
      hostgroups      cameras,fixed-cameras
      }
  </code></pre>
  
  <p>The reason it needs to match the IP is for a bash script to get the correct MAC for the device from its address. </p>
  
  <p>I have awk available as well, should this be a case where awk writes cleaner than sed. </p>
  
  <p>Thanks for your suggestions.</p>