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

1 Answer 1

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.