如何使用python对齐linux输出
我正在尝试对齐如何使用python对齐linux输出,python,linux,bash,command-line,Python,Linux,Bash,Command Line,我正在尝试对齐bash命令的输出 这是我现在使用的命令。我使用python执行这个bash命令,它工作得很好,所以我不打算发布这部分内容 kubectl get pods -n kube-system | awk '/Completed/ {print $1}' 我将这个输出输出到一个名为output 这就是它的输出 akamai-1576314300-xhf78 Completed
bash
命令的输出
这是我现在使用的命令。我使用python
执行这个bash
命令,它工作得很好,所以我不打算发布这部分内容
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)
但是我使用的是这样的输出变量
print("here is the output: "+constant.ICON+output+")
现在,我的输出如下所示:
No need to use python, just pipe it to column -t
:
kubectl get pods -n kube-system | awk '/Completed/ {print $1}' | column -t
无需使用python,只需将其输送到列-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
e、 g
-
老实说,这回答了我的另一个问题,而不是我问的问题。我想要的是每一行前面都有空格。我不知道如何添加它们column-t
只会让它更像是一个justify。我想要的是在每行前面添加一个固定数量的空格
$ 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