Picking up from Daniel Beck's answer above, this information is indeed stored in the file's resource fork. Apple provides two utilities, called "Rez" and "DeRez" with the developer tools, which allow you to manipulate resource forks. In particular, you can push a resource fork into a file with Rez.
To change the association of a single file from the command line, first create a file of the right type, and manually change its association to the application you want it to open in. This creates the resource fork in the file - if you don't do this, there'll be no information to copy out. Then, pull out the resource fork with DeRez, like this (assuming a file foo.txt, and that the application you want to use is Firefox.app).
DeRez foo.txt > foo.r
This will create a file called foo.r which is the decompiled resource fork as a text file. It will look something like this:
data 'usro' (0) {
$"0000 001A 2F41 7070 6C69 6361 7469 6F6E" /* ..../Application */
$"732F 4669 7265 666F 782E 6170 7000 0000" /* s/Firefox.app... */
$"0000 0000 0000 0000 0000 0000 0000 0000" /* ................ */
You can edit this if you want to create one from scratch, but you have to get the format exactly right or it won't work. It's just hex-encoded characters describing the path to the app bundle you want, terminated with a zero.
You might see a message saying that the resource fork is empty and uninitialised. If so, you haven't changed the per-file association on the source file, so you need to go do that, then re-run the DeRez command.
Once you have this, you can push this into another file as follows (assuming bar.txt exists):
Rez foo.r -a -o bar.txt
This updates bar.txt in place with the resource fork from foo.r.
To check it worked OK, since neither Rez nor DeRez print error messages, just do this:
DeRez bar.txt
You should see the same information as before. After all that, just open the file bar.txt as you normally would, and it should open in the correct application, not the default one.
To do a batch change, once you have the .r file, then you can use a standard wildcard expansion like this:
Rez foo.r -a -o *.txt
That'll do all the files that match the wildcard.
I have done this on 10.7, but it's my understanding that this works on earlier machines too.