Redian新闻
>
问一个Unix Shell Script 的问题
avatar
问一个Unix Shell Script 的问题# Unix - 噫吁兮,危乎高哉
l*l
1
我想输出一些user logon information 到标准输出
老师要求输出格式必须整齐...也就是说每个域都是左边对齐的
可是单独用 "\t" 的时候, 由于有的域名长有的域名短,
还是会参差不齐...
有什么办法可以让我固定输出位置吗?
就象 c 里面 printf("%f10.5", float1) 之类的?
avatar
c*t
2
Just cut off the extra length of the domain name.

【在 l********l 的大作中提到】
: 我想输出一些user logon information 到标准输出
: 老师要求输出格式必须整齐...也就是说每个域都是左边对齐的
: 可是单独用 "\t" 的时候, 由于有的域名长有的域名短,
: 还是会参差不齐...
: 有什么办法可以让我固定输出位置吗?
: 就象 c 里面 printf("%f10.5", float1) 之类的?

avatar
h*a
3
printf in awk support the c-like syntax.

【在 c*****t 的大作中提到】
: Just cut off the extra length of the domain name.
avatar
p*a
4
printf "%-10d\t%-10.5f\n" $1 $2
something like this will do it.
'-' means left aligned.

【在 l********l 的大作中提到】
: 我想输出一些user logon information 到标准输出
: 老师要求输出格式必须整齐...也就是说每个域都是左边对齐的
: 可是单独用 "\t" 的时候, 由于有的域名长有的域名短,
: 还是会参差不齐...
: 有什么办法可以让我固定输出位置吗?
: 就象 c 里面 printf("%f10.5", float1) 之类的?

avatar
l*l
5
;p thanks a lot
echo $user | awk '{printf "%-17s", $0}'

【在 h******a 的大作中提到】
: printf in awk support the c-like syntax.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。