在bash中右对齐/编号

前端之家收集整理的这篇文章主要介绍了在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个空间)

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

原文链接:https://www.f2er.com/bash/388073.html

猜你在找的Bash相关文章