Here is what I have currently:
rename -n 's/(d+).txt/sprintf "%03d", $1/e' ./*.txt
This adds leading zeros but unfortunately drops an extension:
rename(./1.txt, ./001)
rename(./2.txt, ./002)
rename(./3.txt, ./003)
I tried the following, but this didn’t help:
rename -n 's/(d+)(.txt)/sprintf "%03d", $1/e$2' ./*.txt
How to make it work?
New contributor
nick is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.