当前位置: 技术问答>linux和unix
awk 新手 About printf format
来源: 互联网 发布时间:2016-05-17
本文导语: LogonReport.txt 的内容: 02/02/2009 10:19:10 #aa###127.0.0.1#Invalid User ID 02/02/2009 10:21:07 #super#super#IT#127.0.0.1#Invalid Password 02/02/2009 10:21:13 #super#super#IT#127.0.0.1#Invalid Password Shell的内容: awk -F# 'BEGIN { print"------------...
LogonReport.txt 的内容:
02/02/2009 10:19:10 #aa###127.0.0.1#Invalid User ID
02/02/2009 10:21:07 #super#super#IT#127.0.0.1#Invalid Password
02/02/2009 10:21:13 #super#super#IT#127.0.0.1#Invalid Password
Shell的内容:
awk -F# 'BEGIN {
print"----------------------------------------------------------------------------------------------------------------------------------"
print"User IDttUser NametDepartmenttDate TimettIPttFaild Reason"
print"----------------------------------------------------------------------------------------------------------------------------------"}
{printf "%-15s %sn", $2,$3,$4,$1,$5,$6}' LoginReport.txt
期望输出:
----------------------------------------------------------------------------------------------------------------------------------
User ID User Name Department Date Time IP Faild Reason
----------------------------------------------------------------------------------------------------------------------------------
aa 02/02/2009 10:19:10 127.0.0.1 Invalid User ID
super super IT 02/02/2009 10:21:07 127.0.0.1 Invalid Password
super super IT 02/02/2009 10:21:13 127.0.0.1 Invalid Password
02/02/2009 10:21:48 127.0.0.1 Invalid User ID
但实际输出为:
----------------------------------------------------------------------------------------------------------------------------------
User ID User Name Department Date Time IP Faild Reason
----------------------------------------------------------------------------------------------------------------------------------
aa
super super
super super
请高手指教。
02/02/2009 10:19:10 #aa###127.0.0.1#Invalid User ID
02/02/2009 10:21:07 #super#super#IT#127.0.0.1#Invalid Password
02/02/2009 10:21:13 #super#super#IT#127.0.0.1#Invalid Password
Shell的内容:
awk -F# 'BEGIN {
print"----------------------------------------------------------------------------------------------------------------------------------"
print"User IDttUser NametDepartmenttDate TimettIPttFaild Reason"
print"----------------------------------------------------------------------------------------------------------------------------------"}
{printf "%-15s %sn", $2,$3,$4,$1,$5,$6}' LoginReport.txt
期望输出:
----------------------------------------------------------------------------------------------------------------------------------
User ID User Name Department Date Time IP Faild Reason
----------------------------------------------------------------------------------------------------------------------------------
aa 02/02/2009 10:19:10 127.0.0.1 Invalid User ID
super super IT 02/02/2009 10:21:07 127.0.0.1 Invalid Password
super super IT 02/02/2009 10:21:13 127.0.0.1 Invalid Password
02/02/2009 10:21:48 127.0.0.1 Invalid User ID
但实际输出为:
----------------------------------------------------------------------------------------------------------------------------------
User ID User Name Department Date Time IP Faild Reason
----------------------------------------------------------------------------------------------------------------------------------
aa
super super
super super
请高手指教。
|
{printf "%-15s %sn", $2,$3,$4,$1,$5,$6}明显有问题,参数个数不匹配啊,应写成:
{printf "%-15s %s %s %s %s %sn", $2,$3,$4,$1,$5,$6}
{printf "%-15s %s %s %s %s %sn", $2,$3,$4,$1,$5,$6}
|
有几个参数就得有几个指示,楼上说的对。