Bourne Shell 左右对齐 [英] Bourne Shell Left Right Justify

查看:24
本文介绍了Bourne Shell 左右对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对脚本中的输出数据进行一些格式化,而不是积极地如何进行左对齐和宽度对齐.有人能指出我正确的方向吗?

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?

推荐答案

你可以使用 printf.例子

you can use printf. examples

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

像 awk 这样的工具也有格式化功能

tools like awk also has formatting capabilities

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

这篇关于Bourne Shell 左右对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆