What is the best way, using Bash, to rename files in the form:
(foo1, foo2, ..., foo1300, ..., fooN)
With zero-padded file names:
(foo00001, foo00002, ..., foo01300, ..., fooN)
See Question&Answers more detail:osWhat is the best way, using Bash, to rename files in the form:
(foo1, foo2, ..., foo1300, ..., fooN)
With zero-padded file names:
(foo00001, foo00002, ..., foo01300, ..., fooN)
See Question&Answers more detail:osIt's not pure bash, but much easier with the Perl version of rename
:
rename 's/d+/sprintf("%05d",$&)/e' foo*
Where 's/d+/sprintf("%05d",$&)/e'
is the Perl replace regular expression.
d+
will match the first set of numbers (at least one number)sprintf("%05d",$&)
will pass the matched numbers to Perl's sprintf
, and %05d
will pad to five digits