在bash中右对齐/编号

在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

(想象一下这里有2个空间)

现在,您可以自行决定是否出现问题。

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...