Please be patient, this post will be somewhat long ...
I have a bunch of files, some with a simple and clean name (for example, 1E01.txt), and some with a lot of extra features:
Sample2_Name_E01_-co_032.txt Sample2_Name_E02_-co_035.txt ... Sample12_Name_E01_-co_061.txt
etc. The number after the โSampleโ and the letter + the number after the โNameโ are important here - the rest is one-time. If I get rid of the important parts, the file name comes down to the same pattern as the "clean" file names (2E01.txt, 2E02.txt, ..., 12E01.txt). I managed to rename the files with the following expression (I invented it myself, I donโt know if it is very elegant, but it works fine):
rename -v 's/Sample([0-9]+)_Name_([AZ][0-9]+).*/$1$2\.txt/' *.txt
Now the second part adds a leading zero for single-digit file names, for example, 1E01.txt turns into 01E01.txt. I managed to do this (found and changed it to another StackExchange post):
rename -v 'unless (/^[0-9]{2}.*\.txt/) {s/^([0-9]{1}.*\.txt)$/0$1/;s/0*([0-9]{2}\..*)/$1/}' *.txt
So, I finally got to my question: is there a way to combine both expressions in only one rename command? I know I can make a bash script to automate the process, but I want to find a one-pass renaming solution.
thanks
h.mon source share