您的位置:首页 > 运维架构 > Shell

文本左右对齐排版--shell

2017-09-02 12:54 513 查看

文本左右对齐排版

有文本4.txt如下:

111111111111111111111 98912 张三

222222222222222222 150020 李四四

333333333333333333333 360000 王五

444444444444444444 2332 赵六六

555555555555555555 222 田七

666666666666666666666 999999

简单的文本通过批处理排版



编写代码

#! /bin/bash

file=./4.txt

echo -e "\n左对齐\n"

while read line
do
printf "%-30s %-10d %-10s\n" ${line}
done < ${file}

echo -e "\n右对齐\n"

while read line
do
printf "%30s %10d %10s\n" ${line}
done < ${file}


运行结果



参考文档

文件读取:http://www.cnblogs.com/iloveyoucc/archive/2012/07/10/2585529.html

echo转义:http://www.runoob.com/linux/linux-shell-echo.html

printf 命令:http://www.runoob.com/linux/linux-shell-printf.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息