Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know how to batch prepend one audio file to another audio file and create a separate output for each. E.g.



I need a script that can do the following:

Static.wav + Audio1.wav = Audio1out.wav
Static.wav + Audio2.wav = Audio2out.wav
Static.wav + Audio3.wav = Audio3out.wav
Static.wav + Audio*.wav = Audio*out.wav
(* = wildcard)


share|improve this question
Did you mean concatenate? Are these actually separate files or separate work sheets? – Dave Oct 16 '12 at 11:36
Separate files. WAV audio files to be exact. – Matteo Cuellar Vega Oct 16 '12 at 12:52
So you're looking to actually join 2 songs together programatically? So, you if song 1 was Madona and song 2 was Metallica, you'd end up with Madona and Metallica as 1 song? – Dave Oct 16 '12 at 12:54
Yeah, exactly... Just that I want Madonna prepending all songs (well, not really, but you know!) – Matteo Cuellar Vega Oct 16 '12 at 13:01
Please re-edit.. It still doesn't reflect what you want. – user127350 Oct 16 '12 at 13:32
up vote 5 down vote accepted

Yet another update: This is similar to the solution provided here. This solution uses ffmpeg for conversion (which is something you don't need) and sox for combining the files.

You would only need to do download sox and use it. The script below will do what you want, but the output filenames would not be exactly how you want them to be. But you can handle the renaming part differently.

Create a shell script ( or some other name) with the following commands and run it whenever necessary:

for i in Audio*.wav
    sox -m Static.wav $i {$i}out.wav

Please refer here for more information on using sox.

share|improve this answer
Almost... I wanted to create a batch process where I don't need to define each input file, but where I can use a wildcard or something. Something like Static.wav *.wav > File1new.wav but instead of joining everything together, it outputs separate files for each input. – Matteo Cuellar Vega Oct 16 '12 at 13:12
@MatteoCuellarVega this code will still create separate output files. Please update the question with the exact requirement. – M K Oct 16 '12 at 13:15
Will do, just one question. Executing your shell script return errors... cat: inputfiles/inputfiles/song1.txt: No such file or directory -bash: Outputinputfiles/song1.txt: No such file or directory – Matteo Cuellar Vega Oct 16 '12 at 13:18
I did change the variable (File1) and created the right folder structure if you are wondering... – Matteo Cuellar Vega Oct 16 '12 at 13:20
+1 for M K. You have patience re-re-re-answering this :) – user127350 Oct 16 '12 at 13:39

A fairly simple line would give you the output n.

echo $(cat file1)$(cat filen)
share|improve this answer

do_combine () {

    # Strip the path

    # Parameter expansion with input_filename below strips the extension
    cat "$file" "$input_filename" > "newfile.${input_filename%.*}.wav"

So you can do this:

do_combine "metallica.wav"

and the resulting file is named "newfile.wav" and is a combination of Madonna and Metallica, starting with the material girl herself.

cat is a legitimate method of combining wav files.

So if you wanted to combine all files in a specific direcory:

for file in /path/to/dir/*.wav
    do_combine "$file"

Might be a bug in there, it was done off the cuff. Having a program to combine madonna files would be really awkward to explain.

share|improve this answer
Hey thanks, unfortunately it returns (-bash: newfile./input/*.txt: No such file or directory). No worries however, I'll play around with the script to see if I can get it to work. Thank you. – Matteo Cuellar Vega Oct 16 '12 at 13:59
Ah, I see. Please see the updated script. I'll have it fixed in 2 minutes. – UtahJarhead Oct 16 '12 at 14:11
The issue is that the input filename has a path and I didn't account for it. I added a line that will strip the path out. – UtahJarhead Oct 16 '12 at 14:13
cat is NOT a legit way to combine wav files. some aps might be able to read it but the results are not valid. Use sox or something like that instead! – Bjorn Roche Oct 17 '12 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .