Reputation: 3
I have several files like
file01xyg.mkv file02xyg.mkv file03xyg.mkv file04xyg.mkv file05xyg.mkv file06xyg.mkv
and trying to rename them so they just say 01.mkv 02.mkv
etc
I've tried using the rename command by running:
rename -n -e 's/file0[1-6]xyg.mkv/[1-6].mkv/' *.mkv
But then I just get:
(file01xyg.mkv, [1-6].mkv)
(file02xyg.mkv, [1-6].mkv)
(file03xyg.mkv, [1-6].mkv)
(file04xyg.mkv, [1-6].mkv)
(file05xyg.mkv, [1-6].mkv)
(file06xyg.mkv, [1-6].mkv)
Upvotes: 0
Views: 41
Reputation: 27205
The substitution command has the form s/regex/replacement/
. The replacement is not a regex, therefore [1-6]
inside the replacement is just a literal string.
Use a group ()
and reference the matched part inside the group using \1
:
rename -n 's/file(0[1-6])xyg.mkv/\1.mkv/' *.mkv
Upvotes: 1