reading sd file line by line, intersected with "code"

Have a look at the parse example in Serial Input Basics. It should give you a sense of the process you need to implement.

...R