Bourne Shell Left Right Justify

前端 未结 6 1119
情深已故
情深已故 2020-12-18 14:31

I am trying to do some formatting on output data in a script and not positive how to do Left Right justify as well as width. Can anyone point me in the right direction?

6条回答
  •  Happy的楠姐
    2020-12-18 14:58

    you can use printf. examples

    $ printf "%15s" "col1"
    $ printf "%-15s%-15s" "col1" "col2"
    

    tools like awk also has formatting capabilities

    $ echo "col1 col2" | awk '{printf "%15s%15s\n", $1,$2}'
               col1           col2
    

提交回复
热议问题