fbpx

It can be extremely useful to use the Azure CLI to manage / manipulate your Azure resources from the command-line. However, many of the commands will output a large amount of JSON that can be extremely difficult to read at the command-line. When using the Azure CLI within the Bash shell, you can use a couple techniques to make the JSON output much more readable, and using these techniques will really increase your productivity at the command-line.

Azure CLI 2. 0 Command Output Options

When running many of the Azure CLI 2. 0 commands it will output JSON to the command-line. This can be difficult to read at the command-line, especially when you need to scroll a lot in order to sift through the huge output. To solve this the Azure CLI 2.0 supports the use of the “–output” or “-o” parameters to be appended to commands that allows you to easily modify the format of the commands output.

Here’s the “-o” / “–output” options supported:

  • table – outputs in an easily readable table format
    Azure CLI 2.0: Make Bash Output More Readable 1
  • json – outputs in JSON format
    Azure CLI 2.0: Make Bash Output More Readable 2
  • jsonc – outputs in JSON format with a little color highlighting
    Azure CLI 2.0: Make Bash Output More Readable 3
  • tsv – outputs in a tab delimited format
    Azure CLI 2.0: Make Bash Output More Readable 4

It’s really nice to have output format options, but the “table” option is likely the best to output an easily readable result, and the “jsonc” is probably the second best since it outputs JSON that’s a little easier to read.

Here’s a few example Azure CLI 2.0 commands using the Output parameter:

az resource list -o table

az resource list --output table
Azure CLI 2.0: Make Bash Output More Readable 5
az web app show
-g myblogsite
-n myblogsite
-o table
Azure CLI 2.0: Make Bash Output More Readable 6
az vm list -o table
Azure CLI 2.0: Make Bash Output More Readable 7

Filter Results using GREP

On Linux you can use “grep” to filter the results of the Azure CLI 2.0 command output. You can do this to easily sort out specific data in the result to easily find what you’re looking for.

Here’s an example of using “grep” by piping (via “|”) the results of the Azure CLI 2.0 command to “grep“:

az resource list -o table | grep "asia"
Azure CLI 2.0: Make Bash Output More Readable 8

Here’s another example:

az resource list -o table | grep "blog"
Azure CLI 2.0: Make Bash Output More Readable 9

If you’re using Linux or macOS, then the above techniques should work for you just fine. If you’re using Windows 10, you can install and use the Ubuntu Bash for Windows 10 to get access to the above techniques as well.

Happy scripting!!

Microsoft MVP

Chris Pietschmann is a Microsoft MVP, HashiCorp Ambassador, and Microsoft Certified Trainer (MCT) with 20+ years of experience designing and building Cloud & Enterprise systems. He has worked with companies of all sizes from startups to large enterprises. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.
HashiCorp Ambassador Microsoft Certified Trainer (MCT) Microsoft Certified: Azure Solutions Architect