title: bash - How to append to a sed command with a regex wildcard
body: <p>I'm new to using regex and bash scripts.</p>
  
  <p>I have a file (map.txt) which has contents similar to (there are more headers but they all start with '[DATABASE-*]:</p>
  
  <pre><code>[DATABASE-WRITE-SPEED]
  source=DATABASE-WRITE
  
  [DATABASE-READ-IOPS]
  
  [DATABASE-QUERY-LONG]
  </code></pre>
  
  <p>I also have another file which has a list of server names (server.csv) such as:</p>
  
  <pre><code>Server Name
  
  Server1
  
  Server2
  
  Server3
  </code></pre>
  
  <p>I want to use a sed command that can find the headers in map.txt (i.e. [DATABASE-QUERY-LONG]) and add the Server Name</p>
  
  <p>For example:</p>
  
  <pre><code>[DATABASE-WRITE-SPEED-Server1]
  [DATABASE-READ-IOPS-Server1]
  [DATABASE-QUERY-LONG-Server1]
  
  [DATABASE-WRITE-SPEED-Server2]
  [DATABASE-READ-IOPS-Server2]
  [DATABASE-QUERY-LONG-Server2]
  
  [DATABASE-WRITE-SPEED-Server3]
  [DATABASE-READ-IOPS-Server3]
  [DATABASE-QUERY-LONG-Server3]
  </code></pre>
  
  <p>So far, I have a sed command but it doesn't keep the contents of the searched result whilst appending the server name:</p>
  
  <pre><code>for i in $(awk 'NR&gt;1 {print $2}' server.csv); do
      sed s/\\[DATABASE-.*]/[DATABASE-.* $i]/g map.txt
  done
  </code></pre>
  
  <p>Any help is greatly appreciated</p>