Article 51Q05 Inserting a new line at a specific row with a tab in bash script using sed, along with env variable

Inserting a new line at a specific row with a tab in bash script using sed, along with env variable

by
296.saurabh
from LinuxQuestions.org on (#51Q05)
I have a part of json which looks like below:

{
"openstack": {
"admin": {
"username": "admin",
"password": "password",
"tenant_name": "test"
},
I want to add specific env variables at row no 3, 4, and 5 like $auth_url, $region_name and $endpoint Something like:

{
"openstack": {
"auth_url": $auth_url,
"region_name": $region_name,
"endpoint_type": $endpoint,
"admin": {
"username": "admin",
"password": "password",
"tenant_name": "test"
},

How can I do this in bash with sed, Here $auth_url and other $ are basically env variables that are to be replaced.
Using
set -ex
sed -e '3i\\t"auth_url":$AUTH,' -i account_2.json
sed -e '4i\\t"region_name":$REGION,' -i account_2.json
sed -e '5i\\t"endpoint_type":$ENDPOINT,' -i account_2.json

It is not replacing $auth_url with env variableslatest?d=yIl2AUoC8zA latest?i=DZjQIFzN-M8:D2tUy35qLWY:F7zBnMy latest?i=DZjQIFzN-M8:D2tUy35qLWY:V_sGLiP latest?d=qj6IDK7rITs latest?i=DZjQIFzN-M8:D2tUy35qLWY:gIN9vFwDZjQIFzN-M8
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments