0

输入:

position fst
1 0.6
2 0.8
3 0.9
4 0.3
5 1

这给了我一个标题:

awk '{if ($2>=0.7) print $1}' input > output

但这不是:

awk '{if ($2<0.7) print $1}' input > output

怎么会?

4

2 回答 2

3

在您的第二个示例中,$2<0.7被解释"fst"<"0.7"FALSE

您可以添加NR==1 ||始终打印第一行:

$ awk 'NR==1 || $2<0.7{print $1}' input
position
1
4
于 2012-01-11T12:36:32.337 回答
1

如果您总是想打印标题,请使用:

awk '{if (NR>1) {if ($2>=0.7) print $1} else print $1}'
awk '{if (NR>1) {if ($2<0.7) print $1} else print $1}'
于 2012-01-11T12:27:01.190 回答