grep problem?

Hi all,
$class is a viable of group1.

While, in group1 got 2 type:

But when i use this code :

The output is :

But i want only group1_text.

If you just want the first matching entry then somthing like this will work:

grep "^$class"  | head -1

Hi Chubler_XL,
But if add another group inside :

This code cannot support :

grep "^$class"  | head -1

Assume that $class variable of either group1 or group2 or group3.

This ?

grep "^${class}_text"
grep "^$class_text" filename