Skip to content
Advertisement

shell script to read values from one file and replace it in other file

I would like to replace a set of strings into a new file. Source file file1.json values has to be replaced by values from file1.config into file file2.json. I have following script that is failing to do so.

file1.json

JavaScript

file1.config

JavaScript

run.sh

JavaScript

Error:

JavaScript

file2.json appears, but it has no values replaced.

JavaScript

Advertisement

Answer

Just explaining the comment of @user3159253. Your file1.config should look like this for your code to work properly:

JavaScript

P.S. IMHO the way you do the thing is a bit overelaborate. I’d prefer using sed to complete this task — takes only one string:

JavaScript
Advertisement