From: Jeremy Bopp Date: 2012-03-29T06:48:34+09:00 Subject: Re: copy file into new without dups, eol problem On 03/28/2012 04:25 PM, Jan E. wrote: > Hi, > > Ruby uses the LF character ("\n") for line endings, while Windows uses > the CR LF combination ("\r\n"). > > It seems you have to open the file in binary mode so that the CR LF > don't get converted into LF: > > File.open 'C:/htdocs/new.txt', 'wb+' do |file| > lines = File.open('C:/htdocs/old.txt', 'rb', &:readlines).uniq > file.print *lines > end > > Yeah, this *is* ugly. I wonder why Ruby cannot handle that itself. In Ruby 1.9, which the OP is using, File.readlines /can/ handle this better. You can specify the mode in which to open the file directly as a hash option. Or is the solution "ugly" because you have to manually specify binary mode when opening files? -Jeremy