There’s a small handy tool called “avimerge” for that.
If you want to merge several audio files into one, just take
avimerge -o out.avi -i in1.avi in2.avi [inX.avi]
If you want to replace an audio track (e.g. mp3 by ac3), add -p for adding a new audio track an -A
avimerge -o out.avi -i in.avi -p audio.ac3 -A 0