Question

I need to merge 400 pairs of audio files into 400 output files. The pairs are in one folder with names like this:

  • 001-filename-beg.mp3,
  • 001-filename-end.mp3,
  • 002-filename-beg.mp3,
  • 002-filename-end.mp3,
  • etc.

The second file in each pair should be appended to the first creating a new file for each pair. I'm experimenting with sox and mp3wrap in for loops but my knowledge is lacking. I'm doing this manually in the shell. Example:

sox 001-Red-Throated-Diver-bird.mp3 001-Red-Throated-Diver-espeak.mp3  001-Red-Throated-Diver.mp3 

and it works fine. I would like to automate it for all pairs.

Was it helpful?

Solution

You could do something like this:

for beg in *beg*mp3; do
   new=${beg/beg/whole}              # replace the string "beg" with the string "whole"
   end=${beg/beg/end}                # replace the string "beg" with the string "end"
   echo sox "$beg" "$end" "$new"     # show user what sort of command we plan to run
done

Save that in a file called "go", then type:

chmod +x go
./go

It will show you what it is planning to do without doing anything. If you like what it is planning to do, remove the word "echo" in the second last line and do it again. Maybe back up your files first!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top