title: How to read lines of a file in Ruby
body: <p>I was trying to use the following code to read lines from a file. But when reading a <a href="http://dl.dropbox.com/u/559353/rss20.xml.txt">file</a>, the contents are all in one line:</p>
  
  <pre><code>line_num=0
  File.open('xxx.txt').each do |line|
    print "#{line_num += 1} #{line}"
  end
  </code></pre>
  
  <p>But this <a href="http://dl.dropbox.com/u/559353/new.txt">file</a> prints each line separately.</p>
  
  <hr>
  
  <p>I have to use stdin, like <code>ruby my_prog.rb &lt; file.txt</code>, where I can't assume what the line-ending character is that the file uses. How can I handle it?</p>