gpt4 book ai didi

bash - 在bash中右对齐/填充数字

转载 作者:bug小助手 更新时间:2023-10-28 10:44:55 25 4
gpt4 key购买 nike

在 bash 中打印输出时填充数字的最佳方法是什么,以便数字在屏幕上右对齐。所以这个:

00364.txt with 28 words in 0m0.927s
00366.txt with 105 words in 0m2.422s
00367.txt with 168 words in 0m3.292s
00368.txt with 1515 words in 0m27.238

应该这样打印:

00364.txt with   28 words in 0m0.927s
00366.txt with 105 words in 0m2.422s
00367.txt with 168 words in 0m3.292s
00368.txt with 1515 words in 0m27.238

我在 for 循环中逐行打印这些内容。而且我会知道文件中字数的上限(只是现在还不行)。

最佳答案

对于 bash,使用带有对齐标志的 printf 命令。

例如:

printf '..%7s..' 'hello'

打印:

..  hello..

现在,请自行决定解决问题。

关于bash - 在bash中右对齐/填充数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/994461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com