Replace a null from grep to a number 0 using sed

Hi
I have a file which contains count for a code. Code is first field and count is second field.
I am trying to search the code and get correspond count.

File look like this. temp.out

A 10
B  20

I am searching for C , if C is not there I will have get value 0.

I have written like this to get the count.

c=`grep "C " temp.out | awk '{print $2}'`

But this c is getting a null. How do I change it so that I will get zero instead of null.

Thanks and Regards
dgmm

c=`grep "^C " temp.out || echo 0`

Thanks for the reply. I understand if it does not find , I will replace with Zero.
But if the C is present , it has to print from the file for second field.
The above solution does not work.
I tried both .

c=`grep "C " temp.out | awk '{print $2}' | sed "s/^[0-9]/'0'/g"`
c=`grep "C " temp.out | awk '{print $2}' | sed "s/' '/'0'/g"`

But above does not work.

Try this,

c=`grep "D" temp.out`; c=`[ -n "$c" ] && echo "$c" | awk '{print $2}' || echo "0"`;echo $c

Oops here you go:

c=`awk '/^C / {print $2; i++} END{if(i==0)print "0"}' temp.out`

Hi
It is working now. Both are good solution.

Thank you very much.

:b:

---------- Post updated at 03:41 PM ---------- Previous update was at 03:09 AM ----------

Hi
I am just modifying the my question little bit.
I have data like this
type code count
010 A 20
005 C 30
005 A 10

in this case I am looking for count for each type.
for 010 I do this.

a=`grep "010" temp.out | grep "A " | awk '{print $3}'`

but if it does not find , It returns null.
Can you please correct to get 0 if it does not find.