0

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.

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178

1 Answers1

0

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!

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thank you so much. My files have spaces in filename so I get trouble but I will remove them. I appreciate you solution since I can mostly understand whats happening. – user3035282 Dec 09 '13 at 21:52
  • It may work with spaces as there are double quotes around the $beg, $end and $whole variables, it's just that echo doesn't show them. I think they will be passed to sox though. Try a couple in a dummy directory first. – Mark Setchell Dec 09 '13 at 22:00
  • OK. It works perfectly! Thanks again. Had to remove the last echo. – user3035282 Dec 09 '13 at 22:03
  • Excellent. Please accept my answer with a lovely big green tick if you are happy with it. Otherwise, let me know what else you need a hand with. – Mark Setchell Dec 09 '13 at 22:09
  • OK. I see why now. Thanks for the comments also. – user3035282 Dec 09 '13 at 22:10