Yes, this is quite easy, except that you need to open your input file and to open a different output file (i.e. don't try to rewrite within the same file you are reading from). If you want to retain the original name, then you have to do some file renaming either before or after the main process. (There are some alternatives, such as loading the input into memory first and then writing, but this is the easiest to get started.)

Please let us know if you need help for processing the data lines, but if you have such difficulty the best would be that you show what you have tried and tell why it does not do what you want.