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

文本左右对齐排版

有文本4.txt如下:

111111111111111111111 98912 张三 
222222222222222222 150020 李四四 
333333333333333333333 360000 王五 
444444444444444444 2332 赵六六 
555555555555555555 222 田七 
666666666666666666666 999999

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

这里写图片描述

编写代码


#! /bin/bash


file=./4.txt

echo -e "
左对齐
"

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

echo -e "
右对齐
"

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

运行结果

这里写图片描述

转自

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

原文地址:https://www.cnblogs.com/paul8339/p/9376969.html