简单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
相关文章
相关标签/搜索