Search code examples
linuxbashsox

Find a file, convert and store it in the same sub-directory


I want to convert a .au audio dataset to .wav. It's stored genre-wise in folders (genres -> rock,jazz,metal,etc). I can find the audio files using the command -

find -type f -name '*.au'

But I don't know how to pass that list to sox. Also that list has the sub-directory name appended to it at the beginning. How do I remove that?


Solution

  • Not an expert; take with a pinch of salt:

    Use awk to turn the output of find into sox commands. Then pass those commands as strings to bash, that will interpret them (as if you gave them a script):

    find -type f -name '*.au' | awk '{printf "sox [your format options] %s %s\n",$0,$0".wav" }' | bash
    

    A more elegant and probably better solution would be, I think, using xargs to turn the output of awk into arguments for sox; something like:

    find -type f -name '*.au' | awk '{printf "[your format options] %s %s\n",$0,$0".wav" }' | xargs sox
    

    But I am not sure of how to use xargs, so... you'll probably have to flesh out the details if you want to use that.

    Also that list has the sub-directory name appended to it at the beginning. How do I remove that?

    Why do you want to remove it? You'll need it to reference a file that is in a directory. Aynway, you coud use something like this instead of find:

    ls Files/relationship/ | grep '\.old'