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 variables


{
"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 variables