I’m Trying to get only IP address from below command using Azure cli. But it always coming with extra "".
az network nic ip-config list --resource-group "RG_TEST" --nic-name "TEST_NIC6768" --query "[0].privateIpAddress"
Output: "10.244.4.4"
Required Output: 10.244.4.4
2
Answers
Pipe the output to
|ForEach-Object Trim '"'
to have PowerShell automatically strip leading and trailing"
‘s from the output:The
az
CLI outputs JSON data by default, which in the case of a string value means that it is output with enclosing"..."
.While you can remove those
"
characters afterwards, it is better to askaz
not to include them in the first place, which you can do with--output tsv
(-o tsv
):Note:
--output tsv
requests the output in TSV (tab-separated values) form, which in the case of a single string means that it is printed as-is (verbatim); aside from not having to remove enclosing"..."
, this also means that you never need to worry about unescaping JSON-escaped characters such asand embedded
"
.az
supports additional output formats.The quick-and-dirty alternative is to simply remove all
"
chars. with a-replace
operation: