file1.txt
:
{ "somedata": { "common_examples": [ { "text": "yes", "intent": "affirm" }, { "text": "yep", "intent": "affirm" } ], "xyz_synonyms": [], "regex_features": [] } }
file2.json
:
{ "name" : "jobname", "pattern":"[A-Z]+-[0-9]" }, { "name" : "project", "pattern":"[A-Z]{4}" }
输出file.json
:
{ "somedata": { "common_examples": [ { "text": "yes", "intent": "affirm" }, { "text": "yep", "intent": "affirm" } ], "xyz_synonyms": [], "regex_features": [ { "name" : "jobname", "pattern":"[A-Z]+-[0-9]" }, { "name" : "project", "pattern":"[A-Z]{4}" } ] } }
答案 0 :(得分:-2)
使用sed
流编辑器
sed "s/\"regex_features\": \[\]/\"regex_features\": \[ $(cat file2.json) \]/g" file1.txt
输出
➜ ~ sed "s/\"regex_features\": \[\]/\"regex_features\": \[ $(cat file2.json) \]/g" file1.txt
{ "somedata": { "common_examples": [ { "text": "yes", "intent": "affirm" }, { "text": "yep", "intent": "affirm" } ], "xyz_synonyms": [], "regex_features": [ { "name" : "jobname", "pattern":"[A-Z]+-[0-9]" }, { "name" : "project", "pattern":"[A-Z]{4}" } ] } }
这可以工作,但可能并不优雅;-)