title: Merging JSON files using a bash script
body: <p>I am very new to bash scripting. I attempted to write a script that merges several json files. For example:</p>
  
  <p>File 1:</p>
  
  <pre><code>{
    "file1": {
       "foo": "bar"
    }
  }
  </code></pre>
  
  <p>File 2:</p>
  
  <pre><code>{
    "file1": {
       "lorem": "ipsum"
    }
  }
  </code></pre>
  
  <p>Merged File:</p>
  
  <pre><code>{
    "file1": {
      "foo": "bar"
    },
    "file2": {
      "lorem": "ipsum"
    }
  }
  </code></pre>
  
  <p>This is what I came up with: </p>
  
  <pre><code>awk 'BEGIN{print "{"} FNR &gt; 1 &amp;&amp; last_file == FILENAME {print line} FNR == 1 {line = ""} FNR==1 &amp;&amp; FNR != NR {printf ","} FNR &gt; 1 {line = $0} {last_file = FILENAME} END{print "}"}' json_files/* &gt; json_files/all_merged.json
  </code></pre>
  
  <p>It works but I feel there is a better way of doing this. Any ideas?</p>