我正在尝试格式化AWS CLI表格输出,以便它在typora、github md文件等的markdown中显示为一个“不错的”格式化表格。
例如,来自AWS CLI命令的原始表格式输出
$ aws ec2 describe-subnets --query "Subnets[*].{CIDR:CidrBlock,Name:Tags[?Key=='Name']|[0].Value,AZ:AvailabilityZone}" --output table是
----------------------------------------------------------------------
| DescribeSubnets |
+------------+------------------+------------------------------------+
| AZ | CIDR | Name |
+------------+------------------+------------------------------------+
| eu-west-3c| 10.1.103.0/24 | vpc-acme-test-public-eu-west-3c |
| eu-west-3b| 172.31.16.0/20 | None |
| eu-west-3a| 10.1.101.0/24 | vpc-acme-test-public-eu-west-3a |
| eu-west-3c| 10.1.3.0/24 | vpc-acme-test-private-eu-west-3c |
| eu-west-3b| 10.1.2.0/24 | vpc-acme-test-private-eu-west-3b |
| eu-west-3a| 172.31.0.0/20 | None |
| eu-west-3c| 172.31.32.0/20 | None |
| eu-west-3a| 10.1.1.0/24 | vpc-acme-test-private-eu-west-3a |
| eu-west-3b| 10.1.102.0/24 | vpc-acme-test-public-eu-west-3b |
+------------+------------------+------------------------------------+根据分类的markdown教程和测试,在typora和github中正确呈现为表的输出类似于:
| AZ | CIDR | Name |
|------------|------------------|------------------------------------|
| eu-west-3c| 10.1.103.0/24 | vpc-acme-test-public-eu-west-3c |
| eu-west-3b| 172.31.16.0/20 | None |
| eu-west-3a| 10.1.101.0/24 | vpc-acme-test-public-eu-west-3a |
| eu-west-3c| 10.1.3.0/24 | vpc-acme-test-private-eu-west-3c |
| eu-west-3b| 10.1.2.0/24 | vpc-acme-test-private-eu-west-3b |
| eu-west-3a| 172.31.0.0/20 | None |
| eu-west-3c| 172.31.32.0/20 | None |
| eu-west-3a| 10.1.1.0/24 | vpc-acme-test-private-eu-west-3a |
| eu-west-3b| 10.1.102.0/24 | vpc-acme-test-public-eu-west-3b |(上面的文本不会在stackoverflow中呈现为表格。下面是以typora呈现的该表的屏幕截图:

发布于 2020-06-23 14:25:53
我找不到任何AWS CLI选项,但以下类似unix的筛选器系列可以完成此工作。
通过管道将AWS命令的输出发送到:
sed s/'+'/'|'/g | tail -n +4 | head -n -1 完整的CLI命令为:
$ aws ec2 describe-subnets --query "Subnets[*].{CIDR:CidrBlock,Name:Tags[?Key=='Name']|[0].Value,AZ:AvailabilityZone}" --output table | sed s/'+'/'|'/g | tail -n +4 | head -n -1欢迎其他建议!
https://stackoverflow.com/questions/62528553
复制相似问题