Renaming Files using Bash

Everyone loves one-liners. My most needed one in the audio world is renaming files so they can be transferred from one type of system to another. Pyramix (by Merging Technologies) runs only on Windows, and names it's files in a way that no other system does. Pro Tools is not at all customizable. When the mix engineer prints using Pyramix, and the mastering engineer is using Pro Tools (for playback!) then a nice tool is helpful.

Pyramix File names

My (most awesome) mix =MSTR=_##001##_.wav
My (most awesome) mix =MSTR=_##002##_.wav

Pro Tools File names

My (most awesome) mix =MSTR=.L.wav
My (most awesome) mix =MSTR=.R.wav

The difference is Pro Tools uses .L. and .R. and Pyramix uses _#001#_ and _#002#_

As you can see below, no sweat with some google skills, man reading skills, and bash.

Example set of one-liners to execute from a file

for i in *.wav; do mv -v "$i" $( echo $i | tr ' ' '_' ); done;

for i in *.wav; do mv -v "$i" $( echo $i | tr '=' '-' ); done;
for i in *.wav; do mv -v "$i" $( echo $i | tr '(' '-' ); done;
for i in *.wav; do mv -v "$i" $( echo $i | tr ')' '-' ); done;

for i in *.wav; do mv -v "$i"  "${i/"_##002##_"/.R}"; done;

for i in *.wav; do mv -v "$i"  "${i/"_##001##_"/.L}"; done;

With non-geeky people naming files and working with computers, so many characters and spaces get thrown in for little reason. I do a lot of translating of the unwanted characters first, in order to make the substitution work best.

Typically, I'll edit the file with that group of one-liners, and then run the script like so

ProtoolsSystem:~ admin$. rename_pyramix_for_pt.command

This would result in the following (for the Pyramix files above)

My_-most_awesome_mix-_-MSTR-.L.wav
My_-most_awesome_mix-_-MSTR-.R.wav

Now THAT is a workable filename from the command line!

The fun part for me is this

"${i/"_##002##_"/.R}"

String substitution made easy!

ChangingFileNames (last edited 2009-11-12 16:36:28 by localhost)