Remove last occurrence of character (_) and rest of the string in UNIX (sed)

Hi

I need help on this ..!!

Input :

xx_abc_regA
xx_def_regB
xx_qwe_regC

Now i required the output as the below

abc
def
qwe

Need to remove last occurrence of character (_) and rest of the string in Unix (sed).

Thanks in Advance ..!!!

-Nallachand

This is a pretty common problem, I'm sure. You could search the forums before asking such a question. Anyway, here's an example:

sed 's/\(.*\)_.*/\1/' file

balajesuri Thanks..!!

$ sed "s/_[^_]*$//" file
xx_abc
xx_def
xx_qwe