AWE
AWE

Reputation: 4135

Missing header in awk output

input:

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

This gives me a header:

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

but this doesn't:

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

How come?

Upvotes: 0

Views: 2128

Answers (2)

kev
kev

Reputation: 161864

In your second example, $2<0.7 is interpreted as "fst"<"0.7" which is FALSE

You can add NR==1 || to always print first line:

$ awk 'NR==1 || $2<0.7{print $1}' input
position
1
4

Upvotes: 3

anubhava
anubhava

Reputation: 785541

If you always want to print the header then use:

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}'

Upvotes: 1

Related Questions