I prefer the filenames of my MP3 collection to be a bit useful, and consistent at that. Hence, instead of Track 01.mp3 I would much rather see 01 - Title of the Song.mp3, and the same holds for 01_title_of_the_song.mp3. Please give me a nice title-cased name, it's so much friendlier to my eyes.
For the latter, replacing the underscores by spaces is trivial with sed, but uppercasing the first letter proved to be a bit harder. Using sed's y command is not an option, since it transforms all characters in its input. Would there have been the option to only transform the first occurrence, I would have been happy. But alas, no such luck.
At first I thought I had found the solution here, but unfortunately, using the proposed \U and \E turned out to be a no-op. But the solution was nearby, and so my command line became
for a in *.mp3; do mv "$a" "`echo $a | sed -e 's/_/ /g' | awk '{print toupper(substr($0,1,3)substr($0,4,1))substr($0,5)}'`"; done
Now I only need to capitalise a few additional letters. Much better!
Edit: It turned out that I was fooled by my own "knowledge" of regular expressions. Using \d does not really work in sed. It's now for a in *.mp3; do mv "$a" "`echo $a | sed -e 's/_/ /g' -e 's/\([a-z]\)/- \U\1\E/'`"; done :)
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment