How to use grep to check NAN value and nonexistense element in file

Hi,

I have a file which computes fields number and some column produced "nan"
I would like to convert the "nan" value to 0 basically.

q=`echo $i $j |awk '{printf("%f",($2/($1+$2)))}'
The above is the command which I use for computation. However, I would
like to check if $1 and $2 is 0, it will return 0 and echo as q=0 rather than nan.

Besides, I would like to know how can we check nonexistence element from grep

k=`grep -n " $char"'$'"" a.txt.txt|tr ":" " "|awk '{print $1}'

Above is the command which I used to grep and check a value of first field element. However, I would like to check if the grep returns me 0 (none found), it would print a constant value of 1000 let say.

Please help. Thanks.

-Jason

Hi,

I used:-

q=`echo $i $j |awk '{if($1 == 0 && $2 == 0) print "0"}'`

k=`echo $q |awk '{if($1 == 0) print "0"}'`

by adding the above two statements to counter the two possibilities.However, after I added these, the condition where $1 and $2 is not "0" and grep is not "0" could not be printed out.

Is my syntax somehow wrong which cause the q and k to update itself. The way I code them is basically if the condition stated fulfill, the value of q and k shall be updated.

Please advise. Thanks.

-Jason