I'm trying to use sed to replace `[databases]` in pgbouncer.ini with 

```
[databases]
db = host=localhost port=5432 dbname=db user=r00t password=xyz

```

This is my bash script:

```
CR=$(printf '\r')
sed "s/\[databases\]\$/\[databases\]$CR db = host=localhost port=5432 dbname=db user=r00t password=xyz/" pg.ini

```

Unfortunatelly I get only this shown instead:

```
db = host=localhost port=5432 dbname=db user=r00t password=xyz

```

**UPDATE:**

Variables would cause a problem in the accepted answer. I get the error: 

> 
> sed: -e expression #1, char 127: extra characters after command
> 
> 
> 

```
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

```