How do I print some text in bash and pad it with spaces to a certain width?

后端 未结 3 1562
春和景丽
春和景丽 2020-12-14 14:25

I\'m echoing some text in a bash script with a variable in it, and want to pad that variable so it will always have the appropriate ammount of spaces to the right to keep th

3条回答
  •  佛祖请我去吃肉
    2020-12-14 14:46

    Collect all your lines in one var or text file then pipe it through column command. So this (my example file /tmp/columns.txt)

    Echoing random number 1080 [ OK ]
    Echoing random number 44332356 [ OK ]
    Echoing random number 34842 [ OK ]
    Echoing random number 342 [ OK ]
    

    became this

    Echoing  random  number  1080      [  OK  ]
    Echoing  random  number  44332356  [  OK  ]
    Echoing  random  number  34842     [  OK  ]
    Echoing  random  number  342       [  OK  ]
    

    Example command: cat /tmp/columns.txt | column -t

提交回复
热议问题