I have a folder containing the following files:
trackingData-00-1.data, trackingData-00-2.data, ..., trackingData-00-2345.data
And I would like to rename them by formatting numbers with 4 digits
trackingData-00-0001.data, trackingData-00-0002.data, ..., trackingData-00-2345.data
How can I achieve that with a bash shell command?
A pure
bashsolution:A regular expression extracts the number to pad and stores it in the
BASH_REMATCHarray. Thenprintfis used to create the new file name, with the number reinserted and padded with zeros.