shell文本左右对齐排版【转】

文本左右对齐排版

有文本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}

 

运行结果

这里写图片描述

 

转自

文本左右对齐排版--shell - CSDN博客
https://blog.csdn.net/dengjili/article/details/77800546

posted @ 2018-07-27 12:45  paul_hch  阅读(2849)  评论(0编辑  收藏  举报