【awk&printf】shell中用printf&awk 实现
查看rabbitMQ实例中交换器
# rabbitmqctl list_exchanges
该命令还可以附加参数,比如列出交换器的名称、类型、是否持久化、是否自动删除
# rabbitmqctl list_exchanges name type durable auto_delete
用printf&awk 实现格式化输出
# rabbitmqctl list_exchanges name type durable auto_delete | awk '{printf "%-45s %-30s %-30s %-30s\n",$1,$2,$3,$4}'
# rabbitmqctl list_exchanges name type durable auto_delete | grep -v "Listing exchanges ..." | awk 'BEGIN{printf "%-45s %-30s %-30s %-30s\n","name","type","durable","auto_delete"} {printf "%-45s %-30s %-30s %-30s\n",$1,$2,$3,$4}'
# awk -F ":" 'BEGIN{printf "%-20s%-20s%-20s\n","User","UID","Home"} {printf "%-20s%-20s%-20s\n", $1,$3,$6} END{print "Total",NR,"lines."}' /etc/passwd
参考
awk 系列:如何使用 awk 的特殊模式 BEGIN 和 END
https://linux.cn/article-7654-1.html
在shell脚本中登录MySQL并执行SQL语句
https://blog.csdn.net/qq_31598113/article/details/79887960
awk printf
https://www.cnblogs.com/ray-mmss/p/10119397.html
shell编程:awk之printf命令
https://blog.csdn.net/weixin_43443216/article/details/106898584