title: Replace a multiline pattern using Perl, sed, awk
body: <p>I need to concatenate multiple JSON files, so</p>
  
  <pre><code>        ...
          "tag" : "description"
      }
  ]
  [
      {
          "tag" : "description"
          ...
  </code></pre>
  
  <p>into this :</p>
  
  <pre><code>    ...
      "tag" : "description"
  },
  {
      "tag" : "description"
      ...
  </code></pre>
  
  <p>So I need to replace the pattern <code>] [</code> with <code>,</code>, but the new line character makes me crazy...</p>
  
  <p>I used several methods, I list some of them:</p>
  
  <ul>
  <li><p><strong>sed</strong></p>
  
  <pre><code> sed -i '/]/,/[/{s/./,/g}' file.json
  </code></pre>
  
  <p>but I get this error:</p>
  
  <pre><code>sed: -e expression #1, char 16: unterminated address regex
  </code></pre></li>
  <li><p>I tried to delete all the newlines
  <a href="https://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed">following this example</a></p>
  
  <pre><code>sed -i ':a;N;$!ba;s/\n/ /g' file.json
  </code></pre>
  
  <p>and the output file has "^M". Although I modified this file in unix, I used the dos2unix command on this file but nothing happens. I tried then to include the special character "^M" on the search but with worse results</p></li>
  <li><p><strong>Perl</strong>
  (as proposed <a href="http://ask.xmodulo.com/search-and-replace-multi-line-string.html" rel="nofollow noreferrer">here</a>)</p>
  
  <pre><code>perl -i -0pe 's/]\n[/\n,/' file.json
  </code></pre>
  
  <p>but I get this error: </p>
  
  <pre><code>Unmatched [ in regex; marked by &lt;-- HERE in m/]\n[ &lt;-- HERE / at -e line 1.
  </code></pre></li>
  </ul>