I am creating multiple files from a json template file and I need to replace two values in json file by different values which I am storing in variable. Below is how source json look like
Source :
{"parameters": [
{
"name": "dir_parm",
"value": "changethis"
}
],
"targets": [
{
"identifier": "hsotchangethis"
}
]
}
Output what I require:
"parameters": [
{
"name": "dir_parm",
"value": "/apps"
}
],
"targets": [
{
"identifier": "iass02"
}
]
}
In this way json file has to be updated for directory and host name around 40-50 times.
Below is the sed command I tried but it is getting replaced. File name, hostname , directory all are variables\dynamic.
sed -i '/identifier/c\ \"identifier\" : '${bdhostnm}'/g' $fname
Note- I read we can use jq but in the organization it is not allowed. Any suggestion would be helpful
jq, then following could be helpful to you:jq '.parameters[].value |= "/apps" | .targets[].identifier |= "iass02"' Input_file