awk报告0为空字段,而比较报告为负

时间:2016-05-03 19:11:18

标签: awk

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

发生了什么事?

1 个答案:

答案 0 :(得分:1)

您正在测试的是空字符串是否小于0.等效于此

$ awk 'BEGIN{print ""<0}'
1

转换为0归因于printf "%d"。如果你打印它仍然是空字符串。