在 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..
现在,请自行决定解决问题。
https://stackoverflow.com/questions/994461/