I have a little programming experience but am completely new to shell scripting.

I have several hundred mp3s which I want to split using mp3splt with the command

mp3splt -A XXX.txt XXX.mp3

I have run this command by hand in the past but now have a project where doing it by hand would be impractical due to the number of files. In my imagination it should be easy to write a script that searches a folder for all the mp3s that have a txt file of the same name and runs the above command on them.

My question just is this: Is there any obvious reason this would not work? If you (meaning: a person with experience in shell scripting) don´t see any such reason, I´d work my way through this tutorial to work out the rest. If, on the other hand, you say it is impossible, I can just stop and do it by hand.

Thanks in advance!

In case you are interested in my use case: I play irish music, which is based on short melodies played by heart. I want to learn these melodies using anki with audio files. For that, I need to have audio files with just one specific tune each.

  • Kissaki@programming.dev
    link
    fedilink
    English
    arrow-up
    4
    ·
    2 days ago

    My preferred shell is Nushell. I would write:

    glob **/*.mp3 | wrap mp3 | insert txt { $in.mp3 | path parse | update extension 'txt' | path join } | each { ^mp3splt -A $in.txt $in.mp3 }
    

    or with line breaks for readability

    glob **/*.mp3
      | wrap mp3
      | insert txt { $in.mp3 | path parse | update extension 'txt' | path join }
      | each { ^mp3splt -A $in.txt $in.mp3 }
    
    1. glob to find the files (according to pattern from current dir)
    2. wrap list values in a named column
    3. add column txt with extension replaced by txt
    4. => now I have a table with mp3 and txt columns with respective full paths
    5. call mp3splt for each