how to modify this to work with carriage return and newline \r\n ?
Use a text editor. Or post "this".