Extract unique filenames

Hi Unix Gurus,

In a script, I am trying to extract unique text from a set of filenames.
I have certain files like below in a directory:

OPEN_INV_01012011.xls
OPEN_INV_01022011.xls
OPEN_INV_01032011.xls
CLOSE_INV_01012011.xls
CLOSE_INV_01022011.xls

I need to extract just "OPEN_INV_" and ""CLOSE_INV_"

I use the following command:

val=$(ls | sed 's/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\.[^.]*$//' | sort | uniq)
echo val: $val

This works fine. The last 8 characters before the file extension are always MMDDYYYY.

But when I have a file name with additional time stamp like:
OPEN_INV_01012011_1345.xls (here 01012011 is MMDDYYYY and 1345 is HHMM)
I am not able to get the file name part.

Please help me modify the "val" variable.

Thanks
Shankar

Just have it accept anything except digits.

$  echo OPEN_INV_01012011 | sed 's/\([^0-9]*\).*/\1/'
OPEN_INV_
$ echo OPEN_INV_01012011_1345.xls | sed 's/\([^0-9]*\).*/\1/'
OPEN_INV_
$

Corona,

Thanks for the script. The code is fine and it works when the extensions are same.
But my requirement is some thing like below:

OPEN_INV_01012011.xls
OPEN_INV_01022011.xls
OPEN_INV_01012011.txt
OPEN_INV_01022011.txt

Even though the OPEN_INV_ will be same for .xls and .txt, I wanted to have distinction so that I can use them in my code.

Thanks

$ echo OPEN_INV_01012011_1345.xls | sed 's/\([^0-9]*\)[^.]*\(.*\)/\1\2/'
OPEN_INV_.xls
$

Thanks a bunch.