-1

I wanted to organize my mp3 files and rename them using the pattern track##.mp3 where ## is track number.

I need a regular expression that selects the track number, which is the first two characters in the old name.

Example:

01 - Album Artist - track name.mp3

and output should be

track01.mp3

How do I do this? I am trying some find with sed command or just plane rename, but I am not successful. Regular expression is too complicated for me.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
janci
  • 49
  • 6

1 Answers1

1

If you don't have the Perl-style rename, you can use

for fname in *.mp3; do mv "$fname" "track${fname:0:2}.mp3"; done

This uses mv and parameter expansion to extract the first two characters.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116