在awk中打​​印字符串值会导致错误 [英] Printing a string value in awk results in error

查看:113
本文介绍了在awk中打​​印字符串值会导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

fatal: not enough arguments to satisfy format string
    `%s SPT=80'
     ^ ran out for this one

这是我的代码

for ((h = 1 ; h < 4 ; h++ )); do 
    x=$(awk -v i=h -v j=17 'FNR == 2 {printf "%s " $j}' newiptables.log)
        echo $x

这是我的文件

Dec 26 09:17:51 localhost kernel: IN=eth0 OUT= MAC=00:10:c6:a8:da:68:00:90:7f:9c:50:5a:08:00 SRC=198.252.206.16 DST=10.128.1.225 LEN=313 TOS=0x00 PREC=0x00 TTL=64 ID=59334 PROTO=TCP SPT=80 DPT=56506 WINDOW=46535 RES=0x00 ACK PSH URGP=0 
Dec 26 09:17:52 localhost kernel: IN=eth0 OUT= MAC=00:10:c6:a8:da:68:00:90:7f:9c:50:5a:08:00 SRC=198.252.206.16 DST=10.128.1.225 LEN=1440 TOS=0x00 PREC=0x00 TTL=64 ID=47303 PROTO=TCP SPT=80 DPT=56506 WINDOW=46535 RES=0x00 ACK URGP=0 
Dec 26 09:17:52 localhost kernel: IN=eth0 OUT= MAC=00:10:c6:a8:da:68:00:90:7f:9c:50:5a:08:00 SRC=198.252.206.16 DST=10.128.1.225 LEN=1440 TOS=0x00 PREC=0x00 TTL=64 ID=47559 PROTO=TCP SPT=80 DPT=56506 WINDOW=46535 RES=0x00 ACK URGP=0 

推荐答案

问题是awkprintf命令中缺少逗号:

The problem is a missing comma in the printf command for awk:

awk -v i=h -v j=17 'FNR == 2 {printf "%s ", $j}' newiptables.log
                                          ^
                                          |== This is needed

引用手册 :

一个简单的printf语句如下:

 printf format, item1, item2, ...

这篇关于在awk中打​​印字符串值会导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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