That's the Perl rename
, I suppose. Perhaps something like this would work:
rename 's/^(\d+) ([^-])/$1 - $2/' [0-9]*.mp3
Match anything starting with numbers, then a space, then something other than a dash. Replace with the numbers, a dash, and the next character. (The rest of the name is not touched.) Explicitly checking for the dash here so repeated applications don't end up with files like 01 - - Track name.mp3
.
Actually, your second example seems to work, though of course for names where the first digit is a zero. We could change that to any digits and replace my second captured expression with a negative look-ahead to still aboud adding more than one dash.
rename 's/^\d+ (?!-)/$&- /' *.mp3
((?!pattern)
will match a position that is not followed by the pattern
, but the match is zero-width, so it doesn't cause a replacement.)
rename -n 's/ / - /' *.mp3
should do it. that will change only the first space to space-dash-space. test it first with-n
and if it does what you want run it without-n
. – cas Jun 21 '16 at 13:03