嗨,我如何只獲取test-staging-100以下字典中的值
{
"clusters": [
"test-staging-100",
"test-local-1",
"test-dev-50"
]
}
當我運行這個命令時
$cluster = aws list-clusters | Select-String "test-staging"
我不斷得到"test-staging-100",。我不想要引號和逗號,而只想要test-staging-100
uj5u.com熱心網友回復:
看起來awsCLI 回傳的是 JSON 文本,因此最好將其決議為物件圖ConvertFrom-Json并對其進行操作:
$cluster = (aws list-clusters | ConvertFrom-Json).clusters -match 'test-staging'
如果您真的想使用Select-String搜索原始字串輸出(這是不明智的),您必須執行以下操作:
$cluster = (aws list-clusters | Select-String 'test-staging[^"] ').Matches.Value
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/331887.html
