title: Bash. Replace with sed. End of line problem
body: <p>I am trying to search and replace in file using sed. But sed seems to hate end of line special char.</p>
  
  <pre><code>text=$(shuf text.txt)
  echo "This is text:
  $text"
  sed -i "s~%text%~$text~g" t.txt
  </code></pre>
  
  <p>Here is what I get:</p>
  
  <pre><code>This is text:
   line 2
   line 1
   line 3
   line 4
  sed: -e expression #1, char 15: unterminated `s' command
  </code></pre>
  
  <p>I've tried to replace \n with \r but result is not satisfying at all.
  There is an option to do <strong>tr '\n' , '$'</strong> and then do it backwards afterwards but it doesn't seems right.</p>
  
  <p>Help?</p>