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