title: How to insert string or newline before a pattern "Using SED" ( Without replacing the pattern) In MAC OS
body: <p>I have a file with the following content:</p>
  
  <pre><code>aaaabbaaabbaa
  </code></pre>
  
  <p>and i need an output like:</p>
  
  <pre><code>aaaa
  bbaaa
  bbaa
  </code></pre>
  
  <p>I need a new line to be added before first occurrence of <code>'b'</code>. I need only SED command to use in bash</p>
  
  <p>I am using the following command. I know its now the perfect one.. </p>
  
  <p>Can anyone tell me a better command than this. 
  Pl note only SED command i need to use in bash</p>
  
  <pre><code>sed -i.bak  -e 's/bb/qbb/g' input.txt  
  sed -i.bak  -e 's/qbb/\'$'\nbb/g' input.txt
  </code></pre>