簡單Shell案例

使用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           

使用命令進行左對齊bash

[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
相關文章
相關標籤/搜索