You pattern is wrong. For the sample you gave, this seems to match, but I don't have enough data to make sure:
pattern='normal_[[:xdigit:]]{16}_[[:digit:]]{9}_[[:digit:]]{6}_[^_]*_[^_]*_[[:digit:]]*_[[:digit:]]*-[[:digit:]]*-[[:digit:]]*_([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})-[[:xdigit:]]{8}-[[:xdigit:]]{8}-[[:xdigit:]]{8}.mp3'
for file in *.mp3; do [[ $file =~ $pattern ]] && echo ${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/${BASH_REMATCH[3]}; done
2019/12/10
2019/12/13
However, my approach for this would be different.
use find to find the files and generate the date sequentialy.
for ((i=1;i<=31;i++)) ;
do
DATE=$(date -d "2019-11-30 +$i days" +%Y-%m-%d);
find -regextype posix-egrep \
-iregex '.*normal_[[:xdigit:]]{16}_[[:digit:]]{9}_.*'$DATE'-[[:xdigit:]]{8}-[[:xdigit:]]{8}-[[:xdigit:]]{8}.mp3'
-exec echo mv --target-directory=/some/absolute/path/${DATE//-/\/}/ {} +; done
mv --target-directory=/some/absolute/path/2019/12/10/ ./normal_007a02ece6e249d2_940163493_210061_user_sector_23938_22-46-58_2019-12-10-00CA01DF-10270594-00000001.mp3
mv --target-directory=/some/absolute/path/2019/12/13/ ./normal_007a02ece6e249d2_940163493_210061_user_sector_23938_22-46-58_2019-12-13-00CA01DF-10270594-00000001.mp3
Short explanation:
- this will search for files matching the regular expression with the $DATE included hardcoded (adjust your starting date and max value for different ranges)
- using
-exec {} +
it will move batches of files into a directory (for simplicity is the same date)
- remove the echo when you are really sure that the results are OK.
- check again the regex
Edit: if you want to have a hierarchical structure (year/mm/dd) you can either use pattern substitution for date (${DATE//-/\/}
- replaces all dashes with /
), or use $i directly, and limit yourself to a month.
Another approach would be to use -mtime/-ctime instead of the actual date.