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

 

相关文章:

  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-02-08
猜你喜欢
  • 2021-11-20
  • 2021-11-20
  • 2021-09-18
  • 2022-01-09
  • 2021-11-09
  • 2021-09-16
  • 2021-11-25
相关资源
相似解决方案