You are not logged in.
I've done a lot of searching both via google and this forum's search feature. I've found a couple of threads relevant to my needs, but the one here on arch is old, and I was reprimanded for resurrecting it (rightly so), and the one on ubuntu doesn't seem to help. Here are the threads:
https://bbs.archlinux.org/viewtopic.php?id=80943
http://ubuntuforums.org/showthread.php?t=1798126
here is an example some of the audio files that I am processing:
(2007)American Nervoso]$ ls
10 - Stupid Me.mp3 2 - John Woo.mp3 8 - Spitting Black.mp3
11 - Spitting Black (extended version).mp3 3 - Dali's Praying Mantis.mp3 9 - Hives.mp3
12 - Hutton's Great Heat Engine (demo).mp3 4 - Dead for a Minute.mp3 backup
13 - Rejection Spoken Softly (demo).mp3 5 - Oma.mp3 test
14 - John Woo (demo).mp3 6 - Thank God for Worker Bees.mp3
1 - Hutton's Great Heat Engine.mp3 7 - Rejection Spoken Softly.mp3
This is the dir layout: ~/music/Botch/(2007)American Nervoso
The only change that I need to make is to recursively change all single digit files to two digit ones so that "1 - Hutton's Great Heat Engine.mp3" changes to "01 - Hutton's Great Heat Engine.mp3". There are a lot of files involved, and I'm not sure if any of them will have a number for a track title, so for instance, it might read someting like 15 - 3mph On The Freeway.mp3, so I'd like to make sure that it performs this operation only on the first set of digits it encounters.
In another thread it suggested the command: find . -type f -name \*.mp3 -print0|xargs -0 rename 's/\d+/sprintf("%03d",$&)/e'
I can't get that command to work (it does nothing as far as I can tell). I came to the conclusion that I was using the wrong "rename" utility, and have since installed perl-rename. I then ran the command "perl-rename -n "s/_(\d)\.txt/_0\$1\.txt/" *" Which also did nothing. I'm guessing that I'm still using the wrong rename utility?
Any help would be appreciated.
Last edited by Convergence (2011-08-18 00:41:48)
It's a very deadly weapon to know what you're doing
--- William Murderface
Offline
I've also played around with another solution:
find . -type f -name "Track [0-9].mp3" -exec sh -c 'for file; do mv "$file" "${file%[0-9].mp3}0${file##* }"; done' _ {} +
would probably work great if I could figure out how to adapt it to my naming scheme.
it works perfectly if the tracks are literally named "track 1.mp3" etc, but my naming scheme is slightly different.
Last edited by Convergence (2011-08-17 18:32:43)
It's a very deadly weapon to know what you're doing
--- William Murderface
Offline
community/perl-rename works for me:
$ touch {1..10}\ -\ file.mp3
$ perl-rename -n 's/^\d -/0$&/' *
1 - file.mp3 -> 01 - file.mp3
2 - file.mp3 -> 02 - file.mp3
3 - file.mp3 -> 03 - file.mp3
4 - file.mp3 -> 04 - file.mp3
5 - file.mp3 -> 05 - file.mp3
6 - file.mp3 -> 06 - file.mp3
7 - file.mp3 -> 07 - file.mp3
8 - file.mp3 -> 08 - file.mp3
9 - file.mp3 -> 09 - file.mp3
Of course, you can do this with find as well:
find . -type f -name '[[:digit:]] *' -execdir bash -c 'for f in "${@##*/}"; do mv "./$f" "./0$f"; done' _ {} +
Offline
Thank you falconindy; It worked like a charm. I used the bash version, which worked, so I didn't try the perl version. In the future I'll try the perl-rename version because it looks nicer.
I really need to master at least one of these scripting languages.
Last edited by Convergence (2011-08-18 00:42:39)
It's a very deadly weapon to know what you're doing
--- William Murderface
Offline