python - 如何使用python对齐linux输出
问题描述
我正在尝试使bash
命令的输出对齐。
这是我现在使用的命令。我使用执行此bash
命令python
并且它工作正常,所以我不打算发布该部分。
kubectl get pods -n kube-system | awk '/Completed/ {print $1}'
我得到这个输出到一个名为的变量output
这就是它的输出
akamai-1576314300-xhf78 Completed
akamai-1576659900-npb6g Completed
akamai-1576746300-6vdjm Completed
keycloak-setupbhnhc-zskhw Completed
vault-renew-tokens-1576378800-6dp98 Completed
这是我通常使用打印时的外观print(output)
但我正在output
像这样使用这个变量。
print("here is the output: "+constant.ICON+output+")
我的输出现在看起来像这样:
- here is the output:
● - akamai-1576227900-wrkct Completed
akamai-1576314300-xhf78 Completed
akamai-1576400700-6m84q Completed
akamai-1576487100-bnrg7 Completed
akamai-1576573500-g48lq Completed
akamai-1576659900-npb6g Completed
akamai-1576746300-6vdjm Completed
keycloak-setupbhnhc-zskhw Completed
vault-renew-tokens-1576378800-6dp98 Completed
它没有正确对齐。
我真正想要的是这样的:
- here is the output:
● - akamai-1576227900-wrkct Completed
akamai-1576314300-xhf78 Completed
akamai-1576400700-6m84q Completed
akamai-1576487100-bnrg7 Completed
akamai-1576573500-g48lq Completed
akamai-1576659900-npb6g Completed
akamai-1576746300-6vdjm Completed
我怎样才能做到这一点?
我正在考虑将bash
命令输出带到一个数组中,以便我可以正确执行此操作,但我无法将输出输出到array
有什么好的方法可以做到这一点吗?
解决方案
无需使用 python,只需将其通过管道传输到column -t
:
kubectl get pods -n kube-system | awk '/Completed/ {print $1}' | column -t
例如
$ cat file.txt
akamai-1576314300-xhf78 Completed
akamai-1576659900-npb6g Completed
akamai-1576746300-6vdjm Completed
keycloak-setupbhnhc-zskhw Completed
vault-renew-tokens-1576378800-6dp98 Completed
-
$ cat file.txt | column -t
akamai-1576314300-xhf78 Completed
akamai-1576659900-npb6g Completed
akamai-1576746300-6vdjm Completed
keycloak-setupbhnhc-zskhw Completed
vault-renew-tokens-1576378800-6dp98 Completed
推荐阅读
- spring - Spring Security 没有正确拦截?
- ionic-framework - Javascript 事件不适用于 Ionic 4
- kubernetes - Kubernetes CronJob 创建的已完成 pod 在一段时间后被删除
- c++ - 为什么 remove_reference 对函数不起作用?
- javascript - 系统蜂鸣 NodeJS 自定义频率和持续时间
- typescript - 如何在 vue 组件中实现 typescript 代码?
- gojs - GoJS Html 上下文菜单 - 获取 SelectedNode
- list - Prolog 使用追加查找列表的最后一个元素
- c++ - V8:尝试每秒调用 60 次函数时性能不佳
- php - CSS3的背景颜色?ACF / 高级自定义字段