To extract the values you need, from file A, you read it line by line, and use the split function.

The canonical way to store the association between the numbers (2) and keywords (rat) would be to use a hash. Since in your case, the numbers are continuous integers, you could also use an array, depending on what you feel more comfortable with.