The easiest way to convert a file from Matroska container (mkv) to avi is by using the avconv tool from libav-tools, the tool that has replaced ffmpeg in the new Ubuntu distros.

How to install libav-tools in Ubuntu 12.04 and Ubuntu 12.10:
$ sudo apt-get install libav-tools
To convert mkv to mp4, use this oneliner:
$ avconv -i input.mkv -codec copy output.mp4
This tool recognisez the output file type by the file’s extension and the input file is usually autodetected. If not, use the -f flag before input/output or both, to force the file type recognition.