右侧的文本对齐 - 庆典 [英] right text align - bash

查看:164
本文介绍了右侧的文本对齐 - 庆典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。 我的文字应该就在指定的宽度保持一致。我已成功地削减产量所需的大小,但我有问题,把一切右侧

I have one problem. My text should be aligned by right in specified width. I have managed to cut output to the desired size, but i have problem with putting everything on right side

下面是我得到了什么:

#!/usr/local/bin/bash

length=$1
file=$2
echo $1

echo -e "length = $length \t  file = $file "
f=`fold -w$length $file > output`
while read line
do
        echo "line is $line"
done < "output"

感谢

推荐答案

尝试:

printf "%40.40s\n" "$line"

这将使它右对齐宽度为40。如果你不想要截断,下降 0.40 (感谢丹尼斯!):

This will make it right-aligned with width 40. If you want no truncation, drop .40 (thanks Dennis!):

printf "%40s\n" "$line"

例如:

printf "%5.5s\n" abc
printf "%5.5s\n" abcdefghij
printf "%5s\n" abc
printf "%5s\n" abcdefghij

将会打印:

  abc
abcde
  abc
abcdefghij

这篇关于右侧的文本对齐 - 庆典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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