Srinivas
Srinivas

Reputation: 2100

Assign a value to an awk variable

Why does awk not able to print the variable from a condition?

cat CRND0103-2013-WY_Sundance_8_NNW.txt | awk '{ ($7 == '-9999.0') ? a = 'true' : a = 'false'; print $7, a }'

or even awk '{b = 'true'; print b}' does not work. Can anyone tell why this is the case?

Upvotes: 0

Views: 615

Answers (1)

luoluo
luoluo

Reputation: 5533

You should replace ' to " in your statement.

awk '{b = "true"; print b;}' 
          ^    ^

Upvotes: 1

Related Questions