AWS CLI output table as multi columns

AWS/AWS Command Line Interface

  • outline

When using AWS CLI output as a table, if there is a lot of depth, the columns may overlap as one.

  • resolution

Add "|[0]" to end of query.

  • example (Single Column)
aws ec2 describe-network-interfaces --query 'NetworkInterfaces[*].{PublicIP:PrivateIpAddresses[].Association.PublicIp}' --output table
---------------------------
|DescribeNetworkInterfaces|
|DescribeNetworkInterfaces|
|DescribeNetworkInterfaces|
|DescribeNetworkInterfaces|
|DescribeNetworkInterfaces|
|DescribeNetworkInterfaces|
|DescribeNetworkInterfaces|
||       PublicIP        ||
|+-----------------------+|
||  11.111.1.11          ||
|+-----------------------+|
|DescribeNetworkInterfaces|
||       PublicIP        ||
|+-----------------------+|
  • example (Multi Column)
aws ec2 describe-network-interfaces --query 'NetworkInterfaces[*].{PublicIP:PrivateIpAddresses[].Association.PublicIp|[0]}' --output table
---------------------------
|DescribeNetworkInterfaces|
+-------------------------+
|        PublicIP         |
+-------------------------+
|  None                   |
|  None                   |
|  11.111.1.1             |
|  None                   |
|  None                   |
|  None                   |
|  None                   |
|  None                   |
|  None                   |
+-------------------------+
  • reference

https://stackoverflow.com/questions/73236117/aws-cli-output-table-as-single-columns