打印数值<在awk中的NF?

时间:2013-02-18 14:33:38

标签: awk

我使用pgbench运行了一系列测试,记录了结果:

run-params: 1 1 1
transaction type: SELECT only
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
duration: 90 s
number of transactions actually processed: 280465
tps = 3116.254233 (including connections establishing)
tps = 3116.936248 (excluding connections establishing)

run-params: 1 1 2
transaction type: SELECT only
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
duration: 90 s
number of transactions actually processed: 505943
tps = 5621.570463 (including connections establishing)
tps = 5622.811538 (excluding connections establishing)

run-params: 10000 10 3
transaction type: SELECT only
scaling factor: 10000
query mode: simple
number of clients: 10
number of threads: 1
duration: 90 s
number of transactions actually processed: 10
tps = 0.012268 (including connections establishing)
tps = 0.012270 (excluding connections establishing)

我想提取图形的值。试图同时学习AWK。这是我的AWK计划:

/run-params/      { scaling = $2 ; clients = $3 ; attempt = $4 }
/^tps.*excluding/ { print $scaling "," $clients "," $attempt "," $3 }

当我运行它时,我得到以下输出:

$ awk -f b.awk -- b.log 
tps,tps,tps,3116.936248
tps,tps,=,5622.811538
,,0.012270,0.012270

这不是我想要的。

我理解scaling = 1时,1引用字段1,在这种情况下恰好是tps。当scaling = 10000时,因为该行上没有10000个字段,所以返回null。我确实尝试使用"" $2分配缩放和朋友,但无济于事。

如何在后续操作块中使用/报告数值?

1 个答案:

答案 0 :(得分:1)

只需将$放在scaling等前面即可。scaling是变量引用,$scaling是字段引用。