如何得到一个shell脚本中的一行数据 [英] How to get the data in a single line in a shell script
本文介绍了如何得到一个shell脚本中的一行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在用的是亚马逊CLI工具
来写 EC2审计脚本
。我想获取标签,如名称,所有者,成本中心
从 EC2-描述-实例
。
I am using the Amazon Cli tools
to write an ec2 audit script
.I want to fetch the tags like name, owner, cost centre
from the ec2-describe-instances
.
我使用这个命令:
ec2-describe-instances | grep -i "tag" | grep -i -e "name" -e "owner" -e "cost.centre"
请帮忙
推荐答案
您可以通过管道将现有的命令,以 AWK
格式化...
You can pipe your existing command to awk
for formatting ...
ec2-describe-instances | grep -i "tag" | grep -i -e "name" -e "owner" -e "cost.centre" | awk 'BEGIN{FS=OFS="\t"}{a[$1 FS $2 FS $3]=a[$1 FS $2 FS $3]?a[$1FS$2FS$3] FS $4 FS $5:$4 FS $5}END{for(x in a) print x, a[x]}'
这篇关于如何得到一个shell脚本中的一行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文