【发布时间】:2014-04-02 03:06:11
【问题描述】:
我有一个在文件中写入一些数据的 shell 脚本。我想添加一个标题"Instance Details",在打印文件中的实际数据之前应该居中对齐。
我试过这段代码:
out="Instances_$today_date"
awk -F'\t' -v of="$out" '
# (input and other code omitted...)
BEGIN { # Set the printf() format string for the header and the data lines.
fmt = "%-12s %-33s %-15s %s\n"
# Print the header
printf("Instance Details") > of
printf(fmt, "Instance id", "Name", "Owner", "Cost.centre") > of
}'
但执行此代码后我得到的输出:
Instance DetailsInstance id Name Owner Cost.centre
预期输出:
Instance Details
Instance id Name Owner Cost.centre
高度赞赏任何线索。
【问题讨论】:
-
是什么让您期望“实例详细信息”居中显示?
-
这实际上是文件中的标题。
-
请继续。这是一个标题,并且...究竟应该使它居中?你能指出代码中的哪一行是造成这种情况的原因吗?
-
问题已解决,谢谢