Supposed I have five mp3 files:
01-trackfoo.mp3 02-trackbar.mp3 03-trackbaz.mp3 04-trackabc.mp3 05-trackxyz.mp3
Now I give a quick listen to the files (just mplayer on console will do the trick) and I find out that the order is wrong. 05 is actually 02 and the rest will have to be renamed. So first I will do a temp rename:
01-trackfoo.mp3 02-trackbar.mp3 03-trackbaz.mp3 04-trackabc.mp3 00-trackxyz.mp3
Now we need a "shift": 02 should become 03, 03 should become 04 and 04 should become 05. To minimize confusion, ex-05 (now 00) will just be
My approach was this: (perl
rename, by Larry Wall, default here on Debian)
rename 's/0([2-4])([\s\S]+)/0($1+1)$2/' *
as well as (later, after some more RTFM'ing)
rename 's/0([2-4])([\s\S]+)/0($1+1)$2/e' *
None of them worked, especially because the
/e[val] modifier does not accept anything else but evaluations, and will throw an error once you attempt to combine the evaluations with strings. The
bash can do it just fine, e. g.
foo$((1+6)) will be evaluated to
So how can I do this (one-liner preferred, not intending to write a whole standalone script just for this)?