title: Use awk to interpret }{ as RS and output with ORS }\n{
body: <p>I have data that looks like this:</p>
  <pre><code>{&quot;anonymousId&quot;:&quot;abc123&quot;,{&quot;hello&quot;:&quot;world&quot;}}{&quot;anonymousId&quot;:&quot;abc456&quot;,{&quot;hi&quot;: &quot;again&quot;}}
  </code></pre>
  <p>It's as if you took a newline-delimited json file and removed all the newlines.</p>
  <p>I'm trying to use awk to convert it to to ndjson.</p>
  <p>That is, my expected output is this:</p>
  <pre><code>{&quot;anonymousId&quot;:&quot;abc123&quot;,{&quot;hello&quot;:&quot;world&quot;}}
  {&quot;anonymousId&quot;:&quot;abc456&quot;,{&quot;hi&quot;: &quot;again&quot;}}
  </code></pre>
  <p>I don't want to load the entire file into memory <em>(which is why I'm not using sed)</em>, so my thought is I should use <code>}{</code> as row separator.   Then, I figure if I use <code>}\n{</code> as ORS I should get my desired output.</p>
  <p>So I tried this:</p>
  <pre><code>cat my-file.txt | awk -v RS=&quot;}{&quot; -v ORS=&quot;}\n{&quot; '{$1=$1}1'
  </code></pre>
  <p>But it doesn't work!</p>
  <p>Here's the output I get:</p>
  <pre><code>{&quot;anonymousId&quot;:&quot;abc123&quot;,{&quot;hello&quot;:&quot;world&quot;}
  {}
  {{&quot;anonymousId&quot;:&quot;abc456&quot;,{&quot;hi&quot;: &quot;again&quot;}
  {}
  {}
  {
  </code></pre>
  <p>Apart from the constraint of not loading the entire file into memory, I don't care what bash command is used, but my thinking is awk will be the way.  E.g. if <code>tr</code> supported multi-character expressions, that would be fine with me.</p>
  <p>Please help me understand why this isn't working as expected and what I need to change.</p>
  <p>Thanks!</p>
  <p><strong>Update</strong></p>
  <p>Following the answers given, will add some learnings.</p>
  <p>The TLDR is don't use a macOS if you need to do trickier things like this.</p>
  <p>For one this doen't work on mac: <code>echo -e &quot;a\nb\nc\nd\ne\n&quot; | head -n -2</code>; it complains about illegal line parameter, but this is valid on a linux system.</p>
  <p>The other problem was the way awk was working on my (mac) system.</p>
  <p>My awk command was close to correct.</p>
  <p>On linux it produces this output:</p>
  <pre><code>{&quot;anonymousId&quot;:&quot;abc123&quot;,{&quot;hello&quot;:&quot;world&quot;}}
  {&quot;anonymousId&quot;:&quot;abc456&quot;,{&quot;hi&quot;: &quot;again&quot;}}}
  {
  </code></pre>
  <p>So I just have to find a way to trim the trailing <code>}\n{</code> <em>(and as pointed out in the answer, the <code>{$1=$1}</code> is not necessary)</em>.</p>
  <p>But all of those extraneous newlines were due to the screwy implementation of awk on my system ( It wasn't gawk and i'm not sure what it was ).</p>