我需要從JSON中拉出一個子字符串。在下面的JSON文檔中,我需要結束jq '.[].networkProfile.networkInterfaces[].id'
的值換句話說,我只需要A10NICvw4konls2vfbw-data
即可傳遞給另一個命令。我似乎無法弄清楚如何使用grep拉一個子字符串。我看起來似乎是正則表達式的例子,但並沒有取得成功。Linux CLI - 如何從JSON jq + grep獲取子字符串?
[
{
"id": "/subscriptions/blah/resourceGroups/IPv6v2/providers/Microsoft.Compute/virtualMachines/A10VNAvw4konls2vfbw",
"instanceView": null,
"licenseType": null,
"location": "centralus",
"name": "A10VNAvw4konls2vfbw",
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/blah/resourceGroups/IPv6v2/providers/Microsoft.Network/networkInterfaces/A10NICvw4konls2vfbw-data",
"resourceGroup": "IPv6v2"
}
]
}
}
]
前綴代碼/數據有四個空格。請看[編輯幫助](http://stackoverflow.com/editing-help)。 – Cyrus