I'm not sure what you are asking about. Obviously, you need some kind of parser for the text file. Writing one could be easy or not depending on the format of the text file.
please put your code nto code syntax, it is not easy to read your code.
what is the error you get? what is in output file? give us more details, we cant copy your code and debug it