简单Shell案例

使用shell命令进行左对齐或者右对齐

[root@bj-aws-yace-tbj mnt]# cat test.sh 
#! /bin/bash


file=./test.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}
[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

 

posted @ 2018-06-26 16:49  warren1236  阅读(229)  评论(0编辑  收藏  举报