在bash右对齐/键盘的数字 [英] right align/pad numbers in bash

查看:175
本文介绍了在bash右对齐/键盘的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打印在bash输出的时候,这样的数字是右对齐按住屏幕什么是最好的方式,键盘上的数字。因此,这:

What's the best way to pad numbers when printing output in bash, such that the numbers are right aligned down the screen. So this:

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

我是从内循环打印出这些一行行。我会知道的字数上限在一个文件中(只是不是现在)。

I'm printing these out line by line from within a for loop. And I will know the upper bound on the number of words in a file (just not right now).

推荐答案

有关bash中,使用的printf 命令对准标志。

For bash, use the printf command with alignment flags.

例如:

 printf '%7s' 'hello'

打印:

   hello

(2想象有空格)

(Imagine 2 spaces there)

现在,用你的自由裁量权为您的问题。

Now, use your discretion for your problem.

这篇关于在bash右对齐/键盘的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆