Input filename is project.json
, and its content is:
{"package": [ {"path": "src","default": true } ],"name": "Sample","replacements": [ {"filename": "/src/main/CO_Config.xml","stringToReplace": "COMPANYUSERNAME","replaceWith": "COMPANYUSERNAME" }, {"filename": "/src/main/CO Target System.xml","stringToReplace": "ENDPOINT","replaceWith": "ENDPOINT" } ],"namespace": "","sourceApiVersion": "61.0"}
My script below is reading JSON array 'replacements' and tries to replace strings on mentioned filename:
filename="project.json"if [[ ! -f "$filename" || ! -s "$filename" ]]; then return 1;fifor item in $(cat $filename | jq -c ".replacements[]" ); do echo $item # USE ITEM IN BELOW CODE # replaceWithEnv=$(echo $item | jq -r ".replaceWithEnv\"")done
The output I get trims the spaces in "/src/main/CO Target System.xml"
:
{"filename":"/src/main/CO_Config.xml","stringToReplace":"COMPANYUSERNAME","replaceWith":"COMPANYUSERNAME"}{"filename":"/src/main/COTargetSystem.xml","stringToReplace":"ENDPOINT","replaceWith":"ENDPOINT"}