progfile:
$3 < 0 { printf("3rd field is negative. It is: %d\n", $3) }
$3 == 0 { printf("3rd field is zero. It is: %d\n", $3) }
$3 > 0 { printf("3rd field is positive. It is: %d\n", $3) }
INPUT_FILE:
field1 field2
命令:
awk -f progfile input_file
输出:
3rd field is negative. It is: 0
发生了什么事?
答案 0 :(得分:1)
您正在测试的是空字符串是否小于0.等效于此
$ awk 'BEGIN{print ""<0}'
1
转换为0
归因于printf "%d"
。如果你打印它仍然是空字符串。