title: How to replace a pattern with newline (\n) with sed under UNIX / Linux operating systems?
body: <p>I have a txt file which contains:</p>
  
  <pre><code>Some random
  text here. This file
  has multiple lines. Should be one line.
  </code></pre>
  
  <p>I use:</p>
  
  <pre><code>sed '{:q;N;s/\n/:sl:/g;t q}' file1.txt &gt; singleline.txt
  </code></pre>
  
  <p>and get:</p>
  
  <pre><code>Some random:sl:text here. This file:sl:has multiple lines. Should be one line.
  </code></pre>
  
  <p>Now I want to replace the <code>:sl:</code> pattern with <code>newline (\n)</code> character. When I use:</p>
  
  <pre><code>sed 's/:sl:/&amp;\n/g' singleline.txt
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Some random:sl:
  text here. This file:sl:
  has multiple lines. Should be one line.
  </code></pre>
  
  <p>How to <strong>replace</strong> the pattern with newline character instead of <strong>adding</strong> newline character after the pattern?</p>