SimonSellick
Programmer
Hi,
I am faced with filenames of a format x-CCYYMMDD.csv where x can be anything between 1 and 14 characters, examples:
T001-20050901.csv
XY_AB_12_01-20031231.csv
I need to extract the date string and the preceding code into shell variables. For the two files above, the results should be:
$FILENAME $DATE $CODE
T001-20050901.csv 20050901 T001
XY_AB_12_01-20031231.csv 20031231 XY_AB_12_01
Is there a substring() or equivalent function available in the shell, or in awk; or can anyone suggest another way to achieve this? I can rely on the hyphen separator between code and date, but I can't rely on its being the only one (that is, there might be some in the code section as well).
Any pointers gratefully received.
I am faced with filenames of a format x-CCYYMMDD.csv where x can be anything between 1 and 14 characters, examples:
T001-20050901.csv
XY_AB_12_01-20031231.csv
I need to extract the date string and the preceding code into shell variables. For the two files above, the results should be:
$FILENAME $DATE $CODE
T001-20050901.csv 20050901 T001
XY_AB_12_01-20031231.csv 20031231 XY_AB_12_01
Is there a substring() or equivalent function available in the shell, or in awk; or can anyone suggest another way to achieve this? I can rely on the hyphen separator between code and date, but I can't rely on its being the only one (that is, there might be some in the code section as well).
Any pointers gratefully received.