下午好,我有以下dns.json文件,我在其中传递了URL:
{
"CallerReference": "1605534454287",
"Aliases": {
"Quantity": 2,
"Items": [
"tester1.university.com.br",
"tester2.university.com.br",
"tester3.university.com.br",
"end.university.com.br"
]
},
然后,我有一个名为list.txt的文件,其中包含以下几行:
tester1.university.com.br
tester2.university.com.br
tester3.university.com.br
tester4.university.com.br
tester5.university.com.br
tester6.university.com.br
tester7.university.com.br
tester8.university.com.br
我需要读取list.txt文件并将其自动插入dns.json中,它看起来像这样:
{
"CallerReference": "1605534454287",
"Aliases": {
"Quantity": 2,
"Items": [
"tester1.university.com.br",
"tester2.university.com.br",
"tester3.university.com.br",
"tester4.university.com.br",
"tester5.university.com.br",
"tester6.university.com.br",
"tester7.university.com.br",
"tester8.university.com.br",
"end.university.com.br"
]
}
我在外壳方面有很多困难,你们能帮我吗?
使用jq
,这是专门为查询和更新JSON而构建的工具:
jq --rawfile newListStr list.txt '
[$newListStr | split("\n")[] | select(. != "")] as $newList |
["end.university.com.br"] as $suffix |
.Aliases.Items = $newList + $suffix
' <in.json >out.json