perl-rename 1.14-1
Arch Linux: linux 6.2.12.arch1-1
I have a directory/folder with several subdirectories, all are named by one of the following patterns
Status quo of existing patterns
something-AAA-2023-01-BBB (the most common pattern) something-2023-01-AAA.BBB (the 2nd or 3rd most common pattern) 2023-01-AAA-BBB-CCC.DDD (the 2nd or 3rd most common pattern) something-AAA-2023-01-BBB-CCC.DDD 1111-AAA-2023-01-BBB.CCC 1111-2023-01-AAA.BBB About these patterns:
- The "something" always is a string, the "1111" a number.
- One part is a date, formatted by YYYY-MM, represented by "2023-01" for the sake of clarity.
- The parts of 3 capital letters AAA, BBB, etc. sometimes are either normal words which make sense in the context of the whole folder or sometimes are a jumbled combination of letters and numbers which also make sense in the context of the whole thing. All these AAA's, BBB's, etc. are expressions which make sense in the context of the folder.
- Over time, I added additional information into the folder names, which is why there are CCC's and DDD's.
Expected output
Pending their occurence, I would like to have the elements ("1111"., AAA's, BBB's, etc.) be put out like
1111.AAA.2023-01.something.BBB.CCC.DDD I would like to start off by finding/catching the content between the 1st and 2nd hyphen (if it is there).
So far I am at
perl-rename -n 's/^(.+)\-(.+)\-(\d{4}\-\d{2})\-(.+)/\3\.\1\./' * but that is not really "smart". Is there a way to check if the date is between the 1st and 2nd hyhpen or 2nd and 3rd, before the date (\d{4}\-\d{2}) or after? Or rather, do I have to find all the different cases by defining the number of parentheses of content before and after the date? (sorry for my English there)
Or how can I check if the hyphen before that date string is the 2nd hyphen? Finding the nth occurrence of a character will certainly help in the future.
renamecommand1111, AAA, BBB, something