title: How to add a carriage return with sed?
body: <p>I'm trying to use sed to replace <code>[databases]</code> in pgbouncer.ini with </p>
  
  <pre><code>[databases]
  db = host=localhost port=5432 dbname=db user=r00t password=xyz
  </code></pre>
  
  <p>This is my bash script:</p>
  
  <pre><code>CR=$(printf '\r')
  sed "s/\[databases\]\$/\[databases\]$CR db = host=localhost port=5432 dbname=db user=r00t password=xyz/" pg.ini
  </code></pre>
  
  <p>Unfortunatelly I get only this shown instead:</p>
  
  <pre><code>db = host=localhost port=5432 dbname=db user=r00t password=xyz
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Variables would cause a problem in the accepted answer. I get the error: </p>
  
  <blockquote>
    <p>sed: -e expression #1, char 127: extra characters after command</p>
  </blockquote>
  
  <pre><code>sed -i "/\[databases\]/a\
  main_db = host=${MAIN_DB_LOC} port=5432 dbname=${MAIN_DB} user=r00t password=${MAIN_DB_PASSWORD}
  audit_db = host=${AUDIT_DB_LOC} port=5432 dbname=${AUDIT_DB} user=r00t password=${AUDIT_DB_PASSWORD}
  lat_lng_db = host=${LAT_LNG_DB_LOC} port=5432 dbname=${LAT_LNG_DB} user=r00t password=${AUDIT_DB_PASSWORD}
  " /etc/pgbouncer/pgbouncer.ini
  </code></pre>