title: changing single field in multiple files in bash script
body: <p>I have a set of json config files that need to have all instances of a field "datasource" changed based on the contents of a variable
  $GRAPHITEVOL. However, in each file there is a single instance of this field that must not change.</p>
  
  <p>Directory structure with files to edit:</p>
  
  <pre><code>tree grafana
  grafana
  ├── dashboards
  │   ├── multicluster-noc-view.json
  │   ├── solidfire-cluster.json
  │   ├── solidfire-node.json
  │   ├── solidfire-volume.json
  │   ├── solidfire-volume-topn.json
  │   ├── vsphere-esxi-metrics.json
  │   └── vsphere-vm-stats.json
  </code></pre>
  
  <p>An example of the config file contents (snip from JSON blob): </p>
  
  <pre><code>"datasource": "-- Grafana --",     # &lt;- this needs to be left alone
  "datasource": "graphite-db-dev",   # &lt;- Needs to be replaced with contents of $GRAPHITEVOL
  </code></pre>
  
  <p>Current solution from from a bash script:</p>
  
  <pre><code>DASHBOARDS=$(ls grafana/dashboards/*.json)
  sed -i "s/graphite-db/$GRAPHITEVOL/g" $DASHBOARDS
  </code></pre>
  
  <p>So assuming $GRAPHITEVOL was set to "docker-vol-2" then the output after running the script would be:</p>
  
  <pre><code>"datasource": "-- Grafana --",  #Left unchanged
  "datasource": "docker-vol-2",   #Field changed with contents of $GRAPHITEVOL
  </code></pre>
  
  <p>This works, but is very fragile since it won't handle a case where the datasource is anything but "graphite-db-dev". 
  Ideally the sed statement would match/replace any value in the ["datasource": "docker-vol-2"] statement without touching
  any line that matched  ["datasource": "-- Grafana --",]</p>
  
  <p>Thanks in advance for any help!</p>