0

I have this input with null values in it in a tab separated csv file.I wanna check if a value is e.g., >= 800 or not and add the result to a new column.

input

a
623

616
803

output

a     b
623   no
      no
616   no
803   yes

2
awk -v minval=800 'BEGIN{ FS=OFS="\t" }
  FNR==1{ print $0, "b"; next } # print header
  { print $0, ($1 >= minval ? "yes" : "no") }
' file

Output:

a       b
623     no
        no
616     no
803     yes

You don't need an explicit check if the first column is empty. If you compare a string to a number, the number is converted to a string. And the empty string always comes before any non-empty string when compared lexicographically, thus it is never greater or equal to a non-empty string.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.