Actually this was already posted but it was lost on some migration... so here it is again

All the parsing and extraction is implemented by mkvtoolnix, so first step is installing it...

1
sudo apt-get install mkvtoolnix

After this we can see the tracks in the file

1
mkvinfo video.mkv

Maybe doing |grep track it's better seen, for example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ mkvinfo video.mkv |grep Track
|  + Track number: 1 (track ID for mkvmerge & mkvextract: 0)
|  + Track UID: 1
|  + Track type: video
|  + Track number: 2 (track ID for mkvmerge & mkvextract: 1)
|  + Track UID: 6584684576
|  + Track type: audio
|  + Track number: 3 (track ID for mkvmerge & mkvextract: 2)
|  + Track UID: 685789658
|  + Track type: subtitles

In this case we're interested in track number 3 (or 2 for mkvmerge and mkvextract as the tool explains), so we'll extract it with

1
mkvextract tracks video.mkv 2:subtitles

During this process the interface points the subtitles type, so we may want to set the correct extension to the resulting file

1
2
3
4
$ mkvextract tracks video.mkv 2:subtitles
Extracting track 2 with the CodecID 'S_TEXT/ASS' to the file 'subtitulos. Container format: SSA/ASS text subtitles
Progress: 100%
$ mv subtitles subtitles.ssa

And that's all, surely any track can be extracted, by exchanging the 2: for 1: we'd get the audio.