From: Dinakar Desai Date: 2001-12-15T08:47:19+09:00 Subject: [ruby-talk:28556] Re: help with ^M (line endings ) removing Thank you very much for your emails. I used following small script to remove ^M. Please let me know whether it can be imporved in any way ====code start========== #!/usr/bin/env ruby if ARGV.length > 0 name = ARGV[0] else print "USAGE: remove_ms.rb filename" end def remove_ms(filename) puts filename fh = File.new(filename, "r") lines = fh.readlines fh .close fh = File.new(filename, "w") puts lines lines.each do |line| line.gsub!("\015", "") print "damn has ^M character #{line}" fh< From: "Dinakar Desai" > > > > I have some files that were created in windows. When I use vi editor > > the line ending shows as ^M. what is the easiest method to remove them. > > Thank you. > > ruby -i -pe 'gsub(/\015/, "")' somefile > > I think ought to work (I haven't tested it though!!:) > > You could combine that with find, ala > > find -type f -name "*.txt" -exec ruby -i -pe 'gsub(/\015/, "")' {} \; > > for example to process multiple files. . . > > Hope this helps, > > Bill -- Dinakar Desai, Ph.D Clinical Trials Section Mayo Foundation Rochester, MN 55905 Phone: 507-266-2831 Fax: 507-284-0615 email: mnopq@mayo.edu or dinakar_desai@yahoo.com