询问 :
aws ec2 describe-vpcs --region us-east-1 |
grep -w "VpcId\|CidrBlock" |
cut -d ":" -f2 | tr -d '[','"',',','{',' '
排序前的原始输出:
[
{
"VpcId": "vpc-xxxx",
"CidrBlock": "1.0.0.0/16",
"OwnerId": "1234567890"
}
]
[
{
"VpcId": "vpc-xxxx",
"CidrBlock": "2.0.0.0/16",
"OwnerId": "1234567890"
}
]
排序后输出:
vpc-xxxxxx
1.0.0.0/16
1234567890
vpc-xxxxxx
2.0.0.0/16
1234567890
我想要这种格式的输出
vpc-xxxxxx|1.0.0.0|1234567890
vpc-xxxxxx|2.0.0.0|1234567890
有人可以帮我吗?
答案1
我会使用来自 aws 的查询,然后awk
(以及一些tr
)
aws ec2 describe-vpcs --region us-east-1 --query 'Vpcs[].{VpcId: VpcId, CidrBlock: CidrBlock}'|
tr -d '",' |
awk -F: '$1 ~/VpcId/ { vpc=$2 } $1 ~ /CidrBlock/ { printf "%s | %s\n",vpc,$2 } '
这给了(对我来说)
vpc-d98685b3 | 172.31.0.0/16
从原始输出
[
{
"VpcId": "vpc-d98685b3",
"CidrBlock": "172.31.0.0/16"
}
]