假設我有以下json。Bash和jq - 找到包含在變量中的一個關鍵字,並更改它的值
{
"userid":334,
"Parameters": [
{
"ParameterValue": "james", "ParameterKey": "name"
},
{
"ParameterValue": "22", "ParameterKey": "age"
},
{
"ParameterValue": "belfast", "ParameterKey": "city"
},
{
"ParameterValue": "software", "ParameterKey": "career"
}
]
}
我有一些代碼需要JSON並提取所有的鍵和它們的值。
echo $my_json | jq -r '.Parameters[] | .ParameterKey + "=" + .ParameterValue' >> $OUTPUT_FILE
如果我看着我的輸出文件我也有類似這樣:
name=james
age=22
city=belfast
career=software
我如何才能找到,說「事業」,並改變它的值,它被放置在$ OUTPUT_FILE過嗎?實施例下面:
name=james
age=22
city=belfast
career=consultation
謝謝!你知道我會如何改變這一點,如果ParameterValue爲空,那麼在行的開頭添加'#'? – Xenidious
@ Xenidious,在行首開頭加上'#'是什麼意思*?說明它在特定情況下的外觀 – RomanPerekhrest