Tuesday 15 September 2015

linux - Regex - locate nth position from EOL -



linux - Regex - locate nth position from EOL -

i have directory filenames in dot missing, marks origin of file extension:

filename1jpg filename2jpg filename3mpg

i want add together . before 3rd position end of line, filename renamed to:

filename1.jpg filename2.jpg filename3.mpg

most convenient might rename on shell, can't imagine regex that. can help me?

using perl one-liner.

perl -e 'rename $_, s/\.?(...)$/.$1/r <*>'

or using shell rename:

rename 's/\.?(...)$/.$1/' *

regex linux bash perl

No comments:

Post a Comment