使用shell命令进行左对齐或者右对齐
[root@bj-aws-yace-tbj mnt]# cat test.sh #! /bin/bash file=./test.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} [root@bj-aws-yace-tbj mnt]# cat test.txt 12,34,56a ada afd [root@bj-aws-yace-tbj mnt]# sh test.sh 左对齐 12,34,56a 0 ada 0 afd 0 右对齐 12,34,56a 0 ada 0 afd 0
使用命令进行左对齐
[root@bj-aws-yace-tbj mnt]# cat test.txt 12,34,56a ada afd [root@bj-aws-yace-tbj mnt]# column -t test.txt 12,34,56a ada afd