I currently have a file that has a special character ^M inside it.
Bugs,^MMember Name,Entity Number^MPilgrim,1 404 765 909^MLovene,1 406 373 405^MLarry,1 404 867 143^MTom,^MChristine,1 404 803 973^MJacqueline,1 406 053 064
when i try to read this file only the last line is output: Jacqueline,1 406 053 064. I have the follwoing andit does not work?
file.each {|line| puts line }
The
^Myou’re talking about is the carriage return character with value 0x0d. You can get rid of it usingor split file’s contents with it
As pointed out by LBg, some platforms, e.g. Windows, require you to open a file in binary mode to read CR characters.